1.监听概述
监听器的作用是监听web容器的有效期事件,因此它由容器管理
Listenner | Event |
ServletContextListenner | ServletContextEvent |
ServletContextAttributeListenner | ServletContextAttributeEvent |
HttpSessionListener | HttpSessionEvent |
HttpSessionActivationListener | HttpSessionEvent |
HttpSessionAttributeListener | HttpSessionBindingEvent |
HttpSessionBindingListener | HttpSessionBindingEvent |
ServletRequestListener | ServletRequestEvent |
ServletRequestAttributeListener | ServletRequestAttributeEvent |
2.servlet上下文监听
ServletContext可以看成是对web应用的一个整体性存储区域,对应与application
它需要实现两个接口:
(1)ServletContextListenner
方法:ContextInitialized(ServletContextEvent event)
ContextDestoryed(ServletContextEvent event)
(2)ServletContextAttributeListenner
方法:AttributeAdded(ServletContextAttributeEvent event)
AttributeReplaced(ServletContextAttributeEvent event )
AttributeRemoved(ServletContextAttributeEvent event )
3.监听HTTP会话
(1)HttpSessionListener
(2)HttpSessionActivationListener
(3)HttpSessionAttributeListener
(4)HttpSessionBindingListener
4.监听servlet请求
(1)ServletRequestListener
(2)ServletRequestAttributeListener