• 查看在线用户的监听器


    package org.c.base;

    import java.util.Map; import java.util.concurrent.ConcurrentHashMap;

    import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener;

    import org.apache.log4j.Logger; import org.crm.modules.mycfs.CustomerUserBean;

    /**  *  * @author *  */ public class OnlineUserListener implements HttpSessionListener, HttpSessionAttributeListener {

     private final static Logger logger = Logger.getLogger(OnlineUserListener.class);  private static ConcurrentHashMap<Long, CustomerUserBean> onlineUsers = new ConcurrentHashMap<Long, CustomerUserBean>();

     @Override  public void sessionCreated(HttpSessionEvent event) {  }

     @Override  public void sessionDestroyed(HttpSessionEvent event) {   CustomerUserBean user = (CustomerUserBean) event.getSession().getAttribute("User");   if (user != null) {    onlineUsers.remove(user.getUserId());   }  }

     @Override  public void attributeAdded(HttpSessionBindingEvent event) {   if (event.getName().equals("User")) {    CustomerUserBean user = (CustomerUserBean) event.getValue();    onlineUsers.put(user.getUserId(), user);   }  }

     @Override  public void attributeRemoved(HttpSessionBindingEvent event) {   if (event.getName().equals("User")) {    CustomerUserBean user = (CustomerUserBean) event.getValue();    onlineUsers.remove(user.getUserId());   }  }

     @Override  public void attributeReplaced(HttpSessionBindingEvent event) {

     }

     public static Map getOnlineUsers() {   return onlineUsers;  }

    }

  • 相关阅读:
    创建异步Web服务
    MCAD考试计划
    微软面试题
    Reborn
    Qt项目注意事项
    在ASP.Net中两种利用CSS实现多界面
    为ASP.NET控件添加常用的JavaScript操作
    用Split函数分隔字符串
    Microsoft .NET Pet Shop 4.0
    搞定QString,string,char*,CString的互转
  • 原文地址:https://www.cnblogs.com/guanghuiqq/p/2672076.html
Copyright © 2020-2023  润新知