我写的一个在先人数统计,(有代码)为什么注销没有用??
实现人数统计的类的代码:(OnLineCount.java)
package OAWei;
import javax.servlet.*;
import javax.servlet.http.*;
public class OnLineCount implements HttpSessionListener{
private static int currentCount=0;
public OnLineCount(){}
public void sessionCreated(HttpSessionEvent se){
currentCount++;
}
public void sessionDestroyed(HttpSessionEvent se){
if(currentCount>0)
currentCount--;
}
public static int getCurrentCount(){
return currentCount;
}
}
显示人数的代码:(OnLineCount.jsp)
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<%@ page import="OAWei.OnLineCount" %>
<!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=gb2312">
<title>统计在线人数</title>
</head>
<body>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","No-cache");
response.setDateHeader("Expires",0);
session.setAttribute("name","weicairong");
OnLineCount count=new OnLineCount();
out.print(count.getCurrentCount());
%>
<a href="logout.jsp">注销</a>
</body>
</html>
注销的代码:(logout.jsp)
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<!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=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
session.removeAttribute("name");
session.invalidate();
response.sendRedirect("OnLineCount.jsp");
%>
</body>
</html>