小白最近刚接触JSP,在用session对象写一个防刷新计数器时遇到了问题。理想情况下是刷新页面时计数器不+1,仅当关闭浏览器再重新打开时才会+1;可是在Eclipse JavaEE的内部浏览器测试时刷新网页计数器也会+1,不知道出了什么问题,下面贴出代码,恳请各位前辈指教
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%!
int number=0;
synchronized void countpeople(){
number++;
}
%>
<%
if (session.isNew()){
countpeople();
String num=String.valueOf(number);
session.setAttribute("counter", num);
}
%>
您是第<%=session.getAttribute("counter")%>位访问者!
</body>
</html>