JSP中实现网页访问统计的方法(8)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-20 18:33 点击:次
application.setAttribute("count", new Long(count));
}
count = (Long)application.getAttribute("count");
if(session.isNew()){
count++;
application.setAttribute("count", count);
//更新文件目录
CountFileHandler.write2File(request.getRealPath("/") + "count.txt",count);
}
%>
访问人数:<%=count %>
</body>
</html>
<%@page import="org.servlet.count.Counter"%>
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<html>
<head>
<title>java 计数器程序</title>
</head>
<body>
<%
Counter CountFileHandler = new Counter();
long count = 0;
if(application.getAttribute("count") == null){
count = CountFileHandler.readFromFile(request.getRealPath("/") + "count.txt");
application.setAttribute("count", new Long(count));
}
count = (Long)application.getAttribute("count");
if(session.isNew()){
count++;
application.setAttribute("count", count);
//更新文件目录
CountFileHandler.write2File(request.getRealPath("/") + "count.txt",count);
}
%>
访问人数:<%=count %>
</body>
</html>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>