使用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;}
?