Servlet中那些对象需要监听?
域对象
request request监听器 监听request对象的创建和销毁
session session相关监听器 监听session对象的创建和销毁
servletContext servletContext监听器 监听servletContex对象的创建和销毁
application application监听器 监听application对象的创建和销毁
监听器的接口:监听对象创建或销毁的监听接口
1.ServletRequestListener 监听request对象的创建或销毁
监听器中的方法
void requestDestroyed(ServletRequestEvent sre)
The request is about to go out of scope of the web application.
void requestInitialized(ServletRequestEvent sre)
The request is about to come into scope of the web application.
2. session相关监听器 监听session对象的创建或销毁
HttpSessionListener
void sessionCreated(HttpSessionEvent se)
Notification that a session was created.
void sessionDestroyed(HttpSessionEvent se)
Notification that a session is about to be invalidated.
session相关监听器
2.1HttpSessionBindingListener 监听绑定在session上的事件
void valueBound(HttpSessionBindingEvent event)
Notifies the object that it is being bound to a session and identifies the session.
void valueUnbound(HttpSessionBindingEvent event)
Notifies the object that it is being unbound from a session and identifies the session.
2.2HttpSessionActivationListener 监听session的序列化及反序列化的监听器
void sessionDidActivate(HttpSessionEvent se)
Notification that the session has just been activated.
void sessionWillPassivate(HttpSessionEvent se)
Notification that the session is about to be passivated.
3.ServletContextListener 监听servletContex对象的创建或销毁
void contextDestroyed(ServletContextEvent sce)
Notification that the servlet context is about to be shut down.
void contextInitialized(ServletContextEvent sce)
Notification that the web application initialization process is starting.
监听对象属性变化的监听器接口
1.ServletRequestAttributeListener 监听request对象属性变化(添加、移除、修改)的监听器
void attributeAdded(ServletRequestAttributeEvent srae)
Notification that a new attribute was added to the servlet request.
void attributeRemoved(ServletRequestAttributeEvent srae)
Notification that an existing attribute has been removed from the servlet request.
void attributeReplaced(ServletRequestAttributeEvent srae)
Notification that an attribute was replaced on the servlet request.
2.HttpSessionAttributeListener 监听session对象属性变化(添加、移除、修改)的监听器
void attributeAdded(HttpSessionBindingEvent se)
Notification that an attribute has been added to a session.
void attributeRemoved(HttpSessionBindingEvent se)
Notification that an attribute has been removed from a session.
void attributeReplaced(HttpSessionBindingEvent se)
Notification that an attribute has been replaced in a session.
3.ServletContextAttributeListener 监听servletContext对象的创建或销毁
void attributeAdded(ServletContextAttributeEvent scab)
Notification that a new attribute was added to the servlet context.
void attributeRemoved(ServletContextAttributeEvent scab)
Notification that an existing attribute has been removed from the servlet context.
void attributeReplaced(ServletContextAttributeEvent scab)
Notification that an attribute on the servlet context has been replaced.