JavaWeb三大组件
Servlet
Listener
Filter
==============================
JavaWeb监听器
监听器都是借口,需要自行实现 (观察者模式)
JavaWeb中被监听的是:
ServletContext
生命周期监听器ServletContextListener
方法:
开启时调用contextInitialized(ServletContextEvent)
可以在其中放入一些在服务器启动时就要完成的代码
关闭时调用contextDestroyed(ServletContextEvent)
ServletContextAttributeListener
方法:
添加属性时调用attributeAdded(ServletContextAttributeEvent event)
替换属性时调用attributeReplaced(ServletContextAttributeEvent event)
移除属性时调用attributeRemoved(ServletContextAttributeEvent event)
HttpSession
生命周期监听器HttpSessionListener
方法:
创建session调用sessionCreated(HttpSessionEvent)
消毁session时调用sessionDistoryed(HttpSessionEvent)
HttpSessionAttributeListener
方法:
添加属性时调用attributeAdded(HttpSessionBindingEvent event)
替换属性时调用attributeReplaced(HttpSessionBindingEvent event)
移除属性时调用attributeRemoved(HttpSessionBindingEvent event)
ServletRequset
生命周期监听器ServletRequsetListener
方法:
创建request时调用requestCreated(ServletRequsetEvent)
销毁session时调用requsetDistoryed(ServletRequsetEvent)
ServletRequsetAttributeListener
添加属性时调用attributeAdded(ServletRequestAttributeEvent srae)
替换属性时调用attributeReplaced(ServletRequestAttributeEvent srae)
移除属性时调用attributeRemoved(ServletRequestAttributeEvent srae)
=======================================
在web.xml中配置Listener
<Listener>
<Listener-class>ListenerName</Listener-class>
</Listener>
=======================================
感知监听HttpSessionBindingListener、HttpSessionActivationListener
都与HttpSession相关,用来添加到JavaBean上。这两个监听器都不需要在web.xml中配置
Servlet
Listener
Filter
==============================
JavaWeb监听器
监听器都是借口,需要自行实现 (观察者模式)
JavaWeb中被监听的是:
ServletContext
生命周期监听器ServletContextListener
方法:
开启时调用contextInitialized(ServletContextEvent)
可以在其中放入一些在服务器启动时就要完成的代码
关闭时调用contextDestroyed(ServletContextEvent)
ServletContextAttributeListener
方法:
添加属性时调用attributeAdded(ServletContextAttributeEvent event)
替换属性时调用attributeReplaced(ServletContextAttributeEvent event)
移除属性时调用attributeRemoved(ServletContextAttributeEvent event)
HttpSession
生命周期监听器HttpSessionListener
方法:
创建session调用sessionCreated(HttpSessionEvent)
消毁session时调用sessionDistoryed(HttpSessionEvent)
HttpSessionAttributeListener
方法:
添加属性时调用attributeAdded(HttpSessionBindingEvent event)
替换属性时调用attributeReplaced(HttpSessionBindingEvent event)
移除属性时调用attributeRemoved(HttpSessionBindingEvent event)
ServletRequset
生命周期监听器ServletRequsetListener
方法:
创建request时调用requestCreated(ServletRequsetEvent)
销毁session时调用requsetDistoryed(ServletRequsetEvent)
ServletRequsetAttributeListener
添加属性时调用attributeAdded(ServletRequestAttributeEvent srae)
替换属性时调用attributeReplaced(ServletRequestAttributeEvent srae)
移除属性时调用attributeRemoved(ServletRequestAttributeEvent srae)
=======================================
在web.xml中配置Listener
<Listener>
<Listener-class>ListenerName</Listener-class>
</Listener>
=======================================
感知监听HttpSessionBindingListener、HttpSessionActivationListener
都与HttpSession相关,用来添加到JavaBean上。这两个监听器都不需要在web.xml中配置