我尝试使用应用程序对象来记录有多少访问者查看了这个页面,但是在我刷新页面后我关闭了浏览器,当我再次打开浏览器查看这个页面时,记录又回到了我开始刷新的数量。我不知道为什么?
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<html>
<body>
<%
Integer count;
synchronized (application) {
count = (Integer) application.getAttribute("count");
if(count == null)
count = new Integer(0);
count = new Integer(count.intValue() + 1);
application.setAttribute("count", count);
}
%>
This page has been visited <%= count.intValue() %> times!
</body>
</html>