实现HttpServletListener接口
1:在登录时,获取登录人数以及登录集合,放到application作用域中,声明周期比较长,跟随web应用
ServletContext application =request.getSession().getServletContext()
2:在销毁时,将人数减一,将修改集合
3.如果上述不能满足条件,可以实现 HttpServletAttributeListener,这个里面可以监听到put和remove操作,
public void attributeAdded(HttpSessionBindingEvent se) {
}
se.getValue()可以获取到当前的对象(即往session中存储的对象)
至于如何区分是操作的哪个对象暂时还不明确