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超时时间),倒是可以考虑这种解决方案。
监听对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超时时间),倒是可以考虑这种解决方案。
相关文章推荐
- ServletContextListener,HttpSessionListener,ServletRequestListener监听器的使用,使用的详细步骤
- ServletContextListener HttpSessionListener 接口的实现与应用
- HttpSessionListener,ServletContextListener, ServletContextAttributeListener,ServletContainer监听在线人数
- ServletContextListener,ServletRequestListener,HttpSessionListener监听对象的创建与销毁
- ServletContextListener、MyHttpSessionListener、ServletContextAttributeListener、对象绑定解绑、文件钝化活化
- ServletContextListener HttpSessionListener 接口的实现与应用
- HttpSessionListener ServletContextListener
- web程序的初始化问题——ServletContextListener
- 监听器的使用例子 ServletContextListener
- servlet 相关的Listener应用
- ServletContextListener 启动SPRING加载数据到缓存的应用
- ServletContextListener 解析用法
- spring学习之ApplicationContext—— ContextLoaderListener和ContextLoaderServlet
- Spring异常:Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF
- Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener 解决方案
- Java-ServletContextListener
- Servlet JSP Tutorial -- 1.5 ServletContextListener Servlet Listener Example
- ServletContextListener在Springboot中的使用
- cookie&session&servletContext
- ServletContextListener 介绍