日期:2014-05-17 浏览次数:20686 次
<%@ page contentType="text/html;charset=gbk"%> <%@ page import="java.sql.*,java.io.*"%> <%! 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); } %> <h4>您是本站的第<%=session.getAttribute("counter")%>位访问者</h4>