`

4、javaweb listener 应用场景

 
阅读更多
一、统计当前在线人数
   @Override
     public void sessionCreated(HttpSessionEvent se) {
         ServletContext context = se.getSession().getServletContext();
         Integer onLineCount = (Integer) context.getAttribute("onLineCount");
         if(onLineCount==null){
             context.setAttribute("onLineCount", );
         }else{
             onLineCount++;
             context.setAttribute("onLineCount", onLineCount);
         }
     }
 
     @Override
     public void sessionDestroyed(HttpSessionEvent se) {
         ServletContext context = se.getSession().getServletContext();
         Integer onLineCount = (Integer) context.getAttribute("onLineCount");
         if(onLineCount==null){
             context.setAttribute("onLineCount", );
         }else{
             onLineCount--;
             context.setAttribute("onLineCount", onLineCount);
         }
     }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics