Detailed description of attributes change of Jsp listening application range

Source: Internet
Author: User


By adding a listener for application property changes, we can monitor the changes in attributes of our application.

1. Compile a class that implements ServletContextAttributeListener

The code is as follows: Copy code

Package org. Rudiment. Listener;

Import javax. servlet. ServletContextAttributeEvent;
Import javax. servlet. ServletContextAttributeListener;

Public class MyServletContextAttributeListener implements ServletContextAttributeListener
{
// When a new attribute is added, the container will call this method.
@ Override
Public void attributeAdded (ServletContextAttributeEvent arg0 ){
System. out. println ("a new attribute is added:" + arg0.getName () + "value:" + arg0.getValue ());
    }
   
// The container will call this method when deleting an attribute.
@ Override
Public void attributeRemoved (ServletContextAttributeEvent arg0 ){
System. out. println ("an attribute is deleted:" + arg0.getName () + "value:" + arg0.getValue ());
    }
   
// The container will call this method when updating an attribute.
@ Override
Public void attributeReplaced (ServletContextAttributeEvent arg0 ){
System. out. println ("modified an attribute:" + arg0.getName () + "value:" + arg0.getValue ());
    }

}


2. Configure web. xml

The code is as follows: Copy code

<Listener>
<Listener-class> org. Rudiment. Listener. MyServletContextAttributeListener </listener-class>
</Listener>

Related Article

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.