<%@ page contentType="text/html;charset=gb2312" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.text.*" %> <% String filepath = application.getRealPath("/"); String path = filepath+File.separator+"data"+File.separator+"WebCounter.txt"; String passed = (String)session.getValue("passed"); if(passed==null)passed="";passed=passed.trim(); String counter; if(passed.equals("true")) { counter = WebCounter.count(path,true); } else { session.putValue("passed","true"); counter = WebCounter.count(path,true); } String temp; if(counter==null) { temp = ""; } else { temp = counter; } %> <% String str = "0"; //生成日期 SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); java.util.Date currentTime = new java.util.Date(); String strCurrentTime = formatter.format(currentTime); String filename=strCurrentTime+".txt"; //创建写文件 filename = filepath+File.separator+"data"+File.separator+filename; java.io.File f = new java.io.File(filename); if(!f.exists())//如果文件不存,则建立 { f.createNewFile(); try { PrintWriter pw = new PrintWriter(new FileOutputStream(filename)); pw.println(str);//写内容 pw.close(); } catch(IOException e) { e.printStackTrace(); } } //读文件 BufferedReader breader =new BufferedReader(new FileReader(filename)); str = breader.readLine(); breader.close(); int n=Integer.parseInt(str.trim()); n++; str=n+""; try { PrintWriter pw = new PrintWriter(new FileOutputStream(filename)); pw.print(str);//写内容 pw.close(); } catch(IOException e) { e.printStackTrace(); } %>
您是第<%=counter%>位访客