SP/Servlet
Those who have written AWT or swing programs in event processing must be impressed by the event processing mechanism of the desktop program: classes that implement the listener interface can occur in specific events.
Call a specific method to respond to the event.
In fact, we also have a similar event processing mechanism when writing JSP/servle programs. The difference is that
/Servlet registers listener in Web. XML, and the container calls a specific class to implement listener when a specific event occurs.
1.
Listener and event in servlet:
On the JSP 2.0/Servlet
In 2.4, there are eight listener interfaces and six event categories.
Servletcontextlistener Interface
[Interface method]
Contextinitialized () and contextdestroyed ()
[Receive events] servletcontextevent
[Trigger
Sending scenario] when the container loads a web application (for example, starting
Contextinitialized (), and contextdestroyed () is called when the container removes the web application.
() Method.
Servletcontextattributelistener
[Interface method]
Attributeadded (), attributereplaced (), attributeremoved ()
[Receive events]
Servletcontextattributeevent
[Trigger scenario]
If an object is added to the attribute of the application (servletcontext) object, attributeadded () is called. Similarly, when the attribute is replaced and the owner is removed
Attributereplaced () and attributeremoved () are called respectively ().
Httpsessionlistener
[Interface method] sessioncreated () and sessiondestroyed ()
[Receive events]
Httpsessionevent
[Trigger scenario] When a session (httpsession) object is created or eliminated, the two methods are called respectively.
Httpsessionattributelistener
[Interface method] attributeadded (), attributereplaced (), attributeremoved ()
[Connect
Receiving Event] httpsessionbindingevent
[Trigger scenario]
If an object is added to the attribute of the session (httpsession) object, attributeadded () is called. Similarly, when the attribute is replaced or removed
Attributereplaced () and attributeremoved ().
Httpsessionactivationlistener
[Interface method] sessiondidactivate () and sessionwillpassivate ()
[Receive events]
Httpsessionevent
[Trigger scenario]
Activate and passivate are actions used to replace objects. When session objects must be temporarily stored on hard disks or other storage devices for reasons such as resource utilization or load balancing
Object serialization), the action is called passivate, and the action taken when the session object on the hard disk or storage device reloads the JVM is called activate.
Easy to understand, sessiondidactivate () and
Sessionwillpassivate () is called after activeate and before passivate respectively.
Servletrequestlistener
[Interface method] requestinitialized () and requestdestroyed ()
[Receive events]
Requestevent
[Trigger scenario]
The two methods are called when the request (httpservletrequest) object is created or eliminated.
Servletrequestattributelistener
[Interface method] attributeadded (), attributereplaced (), attributeremoved ()
[Connect
Receiving Event] httpsessionbindingevent
[Trigger scenario]
If an object is added to the attribute of the request (httpservletrequest) object, attributeadded () is called. Similarly, the attribute is replaced and the owner is removed.
Attributereplaced () and attributeremoved () are called respectively ().
Httpsessionbindinglistener
[Interface method] valuebound () and valueunbound ()
[Receive events] httpsessionbi