为了启动session监听需要在 web.xml中加入
<listener id="listener_11111111111111">
<listener-class>com.yc.ycportal.userutil.OnlineUserListener</listener-class>
</listener>
查看当前系统访问用户个数jsp如下:
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.*"%>
<html>
<head>
<title>在线用户信息</title>
<meta http-equiv="refresh" content="20">
</head>
<body>
<%
Map map=com.yc.ycportal.userutil.OnlineUser.getUserNameMap();
out.println("目前已经登陆的用户如下:");
out.println("<BR>");
Set set=map.keySet();
Iterator ito = set.iterator();
while(ito.hasNext()){
String memName=""+ito.next();
out.println("用户ID:"+memName);
out.println(" 用户名:"+map.get(memName));
out.println("<BR>");
}
out.print("当前访问系统的总人数为:");
out.print(com.yc.ycportal.userutil.OnlineUser.getOnline());
%>
</body>
</html>