1.ServletContextAttributeListener
监听对ServletContext属性的操作,比如增加/删除/修改
2.ServletContextListener
监听ServletContext,当创建ServletContext时,激发contextInitialized (ServletContextEvent sce)方法;当销毁ServletContext时,激发contextDestroyed (ServletContextEvent sce)方法。
3.HttpSessionListener
监听HttpSession的操作。当创建一个Session时,激发session Created(SessionEvent se)方法;当销毁一个Session时,激发sessionDestroyed (HttpSessionEvent se)方法。
4.HttpSessionAttributeListener
监听HttpSession中的属性的操作。当在Session增加一个属性时,激发attributeAdded (HttpSessionBindingEvent se) 方法;当在Session删除一个属性时,激发attributeRemoved (HttpSessionBindingEvent se)方法;当在Session属性被重新设置时,激发attributeReplaced (HttpSessionBindingEvent se) 方法。
其中,HttpSessionListener中的sessionDestroyed并不会再浏览器关闭的时候立刻执行,只有在session超时的进入到sessionDestroyed方法中,所以想通过HttpSessionListener实现在浏览器关闭时的逻辑处理是不一定行不通的,个人觉得如果所做的逻辑处理允许一定的延迟(大于session超时时间),倒是可以考虑这种解决方案。