This article will introduce you to details about attributes changes in the scope of Jsp listening application. I hope this article will be helpful to you.
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> |