JSP Listener Listener (ii)

Source: Internet
Author: User

Servletcontextattributelistener

It is used to monitor the change of ServletContext , which is the application range, and implements this structure to rewrite three methods

    • Attributeadded () method: automatically called when adding parameters to the application
    • Attributeremoved () method: Called when the parameter in the application is removed
    • Attributereplaced () method: Called when modifying a parameter in application
1  PackageCom.huayu.listener;2 3 Importjavax.servlet.ServletContextAttributeEvent;4 ImportJavax.servlet.ServletContextAttributeListener;5 ImportJavax.servlet.annotation.WebListener;6 @WebListener7  Public classListener3Implementsservletcontextattributelistener{8     9 @OverrideTen      Public voidattributeadded (Servletcontextattributeevent event) { OneString named=event.getname (). toString (); AString value=Event.getvalue (). toString (); -SYSTEM.OUT.PRINTLN ("Application" adds a "+named+" variable value of "+value); -          the     } -  - @Override -      Public voidattributeremoved (Servletcontextattributeevent event) { +String named=event.getname (). toString (); -String value=Event.getvalue (). toString (); +SYSTEM.OUT.PRINTLN ("Application" Removes a "+named+" variable with a value of "+value); A          at          -          -     } -  - @Override -      Public voidattributereplaced (Servletcontextattributeevent event) { inString named=event.getname (). toString (); -String value=Event.getvalue (). toString (); toSystem.out.println ("+named+" Variable value in "Application" changes to "+value); +     } -  the}

Servletrequestlistener

The request to listen to the user arrives, the end of the request

Requestinitialized: The method is triggered when a user request arrives and is initialized

Requestdestroyed: End of user request, triggered when the method is destroyed

Servletrequestattributelistener

Used to listen for changes in the request scope variables

Attributeadded ()

Attributereplaced ()

Attributeremoved ()

1  PackageCom.huayu.listener;2 3 Importjavax.servlet.ServletRequest;4 Importjavax.servlet.ServletRequestAttributeEvent;5 ImportJavax.servlet.ServletRequestAttributeListener;6 Importjavax.servlet.ServletRequestEvent;7 ImportJavax.servlet.ServletRequestListener;8 ImportJavax.servlet.annotation.WebListener;9 Importjavax.servlet.http.HttpServletRequest;Ten @WebListener One  Public classListener4Implementsservletrequestlistener,servletrequestattributelistener{ A  - @Override -      Public voidrequestdestroyed (servletrequestevent arg0) { the  -HttpServletRequest request=(HttpServletRequest) arg0.getservletrequest (); -SYSTEM.OUT.PRINTLN ("---Sent to" +request.getrequesturi () + "Request destroyed-----"); -          +     } -  + @Override A      Public voidrequestinitialized (servletrequestevent arg0) { atHttpServletRequest request=(HttpServletRequest) arg0.getservletrequest (); -SYSTEM.OUT.PRINTLN ("---Sent to" +request.getrequesturi () + "Request initialized-----"); -     } -  - @Override -      Public voidattributeadded (servletrequestattributeevent arg0) { inServletRequest request=arg0.getservletrequest (); -String name=arg0.getname (); toString value=Arg0.getvalue (). toString (); +A property named "+name+" with a value of "+value+" has been added to the System.out.println (request+ "Scope"); -          the     } *  $ @OverridePanax Notoginseng      Public voidattributeremoved (servletrequestattributeevent arg0) { -ServletRequest request=arg0.getservletrequest (); theString name=arg0.getname (); +String value=Arg0.getvalue (). toString (); AA property named "+name+" with a value of "+value+" has been added to the System.out.println (request+ "Scope")); the          +     } -  $ @Override $      Public voidattributereplaced (servletrequestattributeevent arg0) { -ServletRequest request=arg0.getservletrequest (); -String name=arg0.getname (); theString value=Arg0.getvalue (). toString (); -A property named "+name+" with a value of "+value+" has been added to the System.out.println (request+ "scope) and replaced by");Wuyi          the     } -  Wu}

Httpsessionlistener

For monitoring user session creation and destruction

sessioncreated (httpsessionevent se): When session

Called when it is built.

sessiondestroyed (httpsessionevent se)

executes when no client links to the session

Httpsessionattributelistener

Using the same method as above

JSP Listener Listener (ii)

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.