Application of javax. servlet. servletcontextlistener

Source: Internet
Author: User
Tags object serialization

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.