您的位置:首页 > 其它

Servlet中context和session相关listener

2013-02-28 14:00 399 查看
 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超时时间),倒是可以考虑这种解决方案。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: