日期:2014-05-17  浏览次数:20640 次

访问量的问题
Java code

<%@ 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>


以上代码是index.jsp的,把index.jsp和count/count.text上传到jsp服务器上后发现,无论我怎么访问网页count.txt中的数字老是不变,index.jsp中的数字一直不变,可是服务器已开了对count.txt的读写权限,且以上代码在本地测试成功,请问有人知道这是什么原因吗,劳驾了,谢谢

------解决方案--------------------
应该是路径的问题
------解决方案--------------------
input 没有close