import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;public class counter extends HttpServlet{
int cnt; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
HttpSession httpsession=request.getSession(true);
displayCount(httpsession);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ }
public int displayCount(HttpSession httpsession)
{
readCount();
//if (httpsession.isNew())
if (httpsession.getCreationTime()==httpsession.getLastAccessedTime())
cnt++;
writeCount();
return cnt;
}
public void readCount()
{
try
{
FileReader fr=new FileReader ("count.txt");
BufferedReader br=new BufferedReader(fr);
String initial_cnt=br.readLine();
cnt=Integer.parseInt(initial_cnt);
return;
}
catch (Exception e)
{
//System.out.print(e);
//cnt=5;
}
} public void writeCount()
{
try
{
FileWriter fr=new FileWriter("count.txt");
String initial_cnt=Integer.toString(cnt);
fr.write(initial_cnt,0,initial_cnt.length());
fr.close();
return;
}
catch (Exception e)
{
}
}
}
import javax.servlet.http.*;
import java.util.*;
import java.io.*;public class counter extends HttpServlet{
int cnt; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
HttpSession httpsession=request.getSession(true);
displayCount(httpsession);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ }
public int displayCount(HttpSession httpsession)
{
readCount();
//if (httpsession.isNew())
if (httpsession.getCreationTime()==httpsession.getLastAccessedTime())
cnt++;
writeCount();
return cnt;
}
public void readCount()
{
try
{
FileReader fr=new FileReader ("count.txt");
BufferedReader br=new BufferedReader(fr);
String initial_cnt=br.readLine();
cnt=Integer.parseInt(initial_cnt);
return;
}
catch (Exception e)
{
//System.out.print(e);
//cnt=5;
}
} public void writeCount()
{
try
{
FileWriter fr=new FileWriter("count.txt");
String initial_cnt=Integer.toString(cnt);
fr.write(initial_cnt,0,initial_cnt.length());
fr.close();
return;
}
catch (Exception e)
{
}
}
}
http://expert.csdn.net/Expert/topic/1420/1420286.xml?temp=.4952509