监听器--ServletRequestListener接口实现统计在线人数
2011-11-25 15:17
771 查看
案例:统计当前在线人数
OnlineListener
public class OnlineListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent se) {
ServletContext context=se.getSession().getServletContext();
Integer count=(Integer)context.getAttribute("peopleOnline");
if(count==null){//如果是第一个用户ServletContext域中创建属性,并且赋值为1
count=1;
}else{
count++;
}
context.setAttribute("peopleOnline",count);
}
public void sessionDestroyed(HttpSessionEvent se) {
ServletContext context=se.getSession().getServletContext();
Integer count=(Integer)context.getAttribute("peopleOnline");
count--;
context.setAttribute("peopleOnline",count);
}
Index.jsp
<body>
当前在线人数为:${applicationScope.peopleOnline}
%>
</body>
相关文章推荐
- Servlet监听器——实现在线登录人数统计小例子
- java—实现一个监听器HttpServletRequest的创建销毁、在线人数 (56)
- Servlet监听器简介与实现在线人数统计
- Servlet监听器实现网站在线人数统计
- servlet监听器实现在线人数统计
- Servlet监听器——实现在线登录人数统计小例子
- Servlet监听器的简单使用实现统计在线人数
- 用HttpSessionListener与HttpSessionBindingListener实现在线人数统计
- 用HttpSessionListener与HttpSessionBindingListener实现在线人数统计
- 用HttpSessionListener与HttpSessionBindingListener实现在线人数统计
- servlet监听实现统计在线人数功能 附源码下载
- 用HttpSessionListener与HttpSessionBindingListener实现在线人数统计
- 利用servlet的监听器实现在线人数监控的功能
- 监听器实现案例----自定义session扫描器和统计在线用户人数及用户信息
- 利用HttpSessionListener实现网站在线人数统计功能
- 使用HttpSessionListener接口监听Session的创建和失效(可以用于统计在线人数)
- 使用HttpSessionListener和ServletContextListener实现在线人数和历史访问人数统计的问题
- [java]HttpSessionListener实现统计在线人数
- HttpSessionBindingListener接口在线人数统计
- jsp+servlet+java 实现统计在线人数