Java code
int load(File f){
int temp=0;
try{
temp=new Integer(new BufferedReader(new InputStreamReader(new FileInputStream(f))).readLine());
}catch(Exception e){e.getMessage();}
return temp;
}
public synchronized void save(javax.servlet.http.HttpSession session,int c,File f){
try{
int tem=++c;
session.setAttribute("counter",tem);
PrintStream ps=new PrintStream(new FileOutputStream(f));
ps.println(c);
ps.close();
}catch(Exception e){ e.getMessage();}
}
%>
String fileName=getServletContext().getRealPath("/")+"count"+File.separator+"count.txt";
File f=new File(fileName);
int count=load(f);
if(session.isNew()){
save(session,count,f);
}
%>