What is AttributeListener?

This listener lets you track each time any attribute is added to, removed from, or replaced in a session.

Import javax.servlet.http.*;
Public class MyListener implements HttpSessionAttributeListener{
Public void attributeAdded(HttpSessionBindingEvent event){
String name=event.getName();
Object value=event.getValue();
//lets you get the name and value of the attribute that triggered that event
System.out.println(“attributes added: ”+name+”:”+value);}
Public void attributeRemoved(HttpSessionBindingEvent event){
String name=event.getName();
Object value=event.getValue();
System.out.println(“attributes removed: ”+name+”:”+value);}
Public void attributeReplaced(HttpSessionBindingEvent event){
String name=event.getName();
Object value=event.getValue();
System.out.println(“attributes replaced: ”+name+”:”+value);}}


Configuring in DD:

<web-app>
………….
<listener>
<listener-class>
MyListener
</listener-class>
</listener>

No comments:

Post a Comment