如果用遨游浏览器,为什么监听器只能监听第一次登录的用户,只有当第一次登录用户失效后,才能监听第二次的用户?
public class SessionListener implements HttpSessionListener,
HttpSessionAttributeListener {
org.apache.log4j.Logger logger;
public void sessionCreated(HttpSessionEvent arg0) {
}
public void sessionDestroyed(HttpSessionEvent arg0) {
}
@SuppressWarnings("unchecked")
public void attributeAdded(HttpSessionBindingEvent arg0) {
logger = LogInvoker.getSystemLogger(SessionListener.class);
if (arg0.getName().equals(SessionConstants.ONLINE_STAFF)) {
Map onlineSession = (Map) arg0.getSession().getServletContext().getAttribute(SessionConstants.ONLINE_SESSION);
OnLineStaff onlineStaff = (OnLineStaff) arg0.getValue();
if(onlineStaff!=null){
onlineSession = new HashMap();
}
onlineSession.put(onlineStaff.getBsbUser().getUserId() + "", arg0.getSession());
arg0.getSession().getServletContext().setAttribute(SessionConstants.ONLINE_SESSION, onlineSession);
logger.info(onlineStaff.getBsbUser().getUserName() + " logon!");
}
}
public void attributeRemoved(HttpSessionBindingEvent arg0) {
logger = LogInvoker.getSystemLogger(SessionListener.class);
if (arg0.getName().equals(SessionConstants.ONLINE_STAFF)) {
Map onlineSession = (Map) arg0.getSession().getServletContext()
.getAttribute(SessionConstants.ONLINE_SESSION);
OnLineStaff onlineStaff = (OnLineStaff) arg0.getValue();
if (onlineSession != null) {
onlineSession.remove(onlineStaff.getBsbUser().getUserId() + "");
}
logger.info(onlineStaff.getBsbUser().getUserName() + " logoff!");
}
}
public void attributeReplaced(HttpSessionBindingEvent arg0) {
}
}
用遨游打开的第二个相当于别的浏览器的的文件-》新建窗口
并未新开启一个和服务器会话,所以。。。
SessionListener
只有新用户登陆的时候,产生新的Session,才开始进行监听.
[quote]如果用遨游浏览器,为什么监听器只能监听第一次登录的用户,只有当第一次登录用户失效后,才能监听第二次的用户? [/quote]
与遨游浏览器无关,对所有的浏览器都一样。Session在同一个浏览器中所有页面有效。