首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

运用HttpSessionListener统计在线人数

2012-09-23 
使用HttpSessionListener统计在线人数1.新建一个类实现HttpSessionListener接口,并实现sessionCreated和se

使用HttpSessionListener统计在线人数

1.新建一个类实现HttpSessionListener接口,并实现sessionCreated和sessionDestroyed方法

@SuppressWarnings("unchecked")public String online_body(){HttpServletRequest request=ServletActionContext.getRequest();ServletContext application=request.getSession().getServletContext();HashSet<HttpSession> sessions=(HashSet<HttpSession>)application.getAttribute("sessions");if(sessions!=null &&!sessions.isEmpty()){System.out.println(sessions.size());}return null;}

?

热点排行