JSP details-Servlet listener (2)
3. HTTP session listener
HTTP session listener (HttpSession) information, which has four interfaces for listening
(1) HttpSessionListener Interface
The HttpSesionLintener interface monitors the creation and destruction of HTTP sessions in real time. The HttpSessionListener interface provides the following two methods:
A. sessionCreated (HttpSessionEvent event) method to notify the listened object that the session has been loaded or initialized
B. sessionDestroyed (HttpSessionEvent event) method to notify the listener object that the session has been loaded.
(The main method of the HttpSessionEvent class is getSession (). You can use this method to return a session object)
(2) HttpSessionActivationListener Interface
The HttpSessionActivationListener interface monitors HTTP sessions active and passivate. The HttpSessionActivationListener interface provides the following three methods:
A. attributeAdd (HttpSessionBindingEvent event) method: when an object is added to the session, it is the object that the notification is listening.
B. attributeReplaced (HttpSessionBindingEvent event) method: when an object in the session range replaces another object, the notification is sent to the object being listened.
C. attributeRemoved (HttpSessionBindingEvent event) method: when an object is removed from the session range, the system notifies the object to be listened. (HttpSessionBindingEvent class has three main methods: getName (), getSession (), getValues ())
(3) HttpBindingListener Interface
The HttpBindingListener interface monitors the binding information of objects in an HTTP session. It is the only one that does not need to set Listener in web. xml. The HttpBindingListener interface provides the following two methods:
A. valueBound (HttpSessionBindingEvent event) method: This method is automatically called when an object is added to the session range.
B. valueUnBound (HttpSessionBindingEvent event) method: This method is automatically called when an object is removed from the session range.
(4) HttpSessionAttributeListener Interface
The HttpSessionAttributeListener interface allows you to listen to HTTP session attribute setting requests. The HttpSessionAttributeListener interface provides the following two methods:
A. sessionDidActivate (HttpSessionEvent event) method: notifies the listener of the object whose session has changed to A valid state.
B. sessionWillPassivate (HttpSessionEvent event) method: notifies the listener of the object whose session has changed to an invalid state.
4. Servlet Request listening
A technology added to the Servlet2.4 specification is that it can listen to client requests. Once a client request can be obtained, the request can be processed in a unified manner. Two interfaces are required for listening to client requests and request parameter settings:
1. ServletRequestListener Interface
The ServletRequestListener interface provides the following two methods:
A. requestInitialized (ServletRequestEvent event) method: indicates the object to be listened to. ServletRequest has been loaded and initialized.
B. requestDestroyed (ServletRequestEvent event) method: indicates the object to be listened to. When the ServletRequest object is loaded, it is disabled.
2. ServletRequestAttributeListener interface:
The ServletRequestAttibuteListener interface provides the following three methods:
A. attributeAdded (ServletRequestAttributeEvent event) method: when an object is included in the request range, the system notifies the object being listened.
B. attributeReplaced (ServletRequestAttributeEvent event) method: when an object replaces another object within the request range, the notification is being listened.
C. attributeRemoved (ServletReqquesstAttributeEvent event) method: when an object is removed from the request range, the system notifies the object to be listened.