| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs Servlet FAQ:
When do I use HttpSessionAttributeListener?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
When do I use HttpSessionAttributeListener?
The This can be useful when you know the name assigned to a specific object that gets put into the session and you want to track how often it's being used. For example,
package mypackage;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
public final class MySessionAttributeListener implements HttpSessionAttributeListener {
public void attributeAdded(HttpSessionBindingEvent event) {
System.out.println("attributeAdded");
System.out.println(event.getSession().getId());
System.out.println(event.getName() + "', '" + event.getValue());
}
public void attributeRemoved(HttpSessionBindingEvent event) {
System.out.println("attributeRemoved");
System.out.println(event.getSession().getId());
System.out.println(event.getName() + "', '" + event.getValue());
}
public void attributeReplaced(HttpSessionBindingEvent event) {
System.out.println("attributeReplaced");
System.out.println(event.getSession().getId());
System.out.println(event.getName() + "', '" + event.getValue());
}
}
As with <listener> <listener-class>mypackage.MySessionAttributeListener</listener-class> </listener>
The
public void attributeReplaced(HttpSessionBindingEvent se) : Notification that an attribute has been replaced in a session. Called after the attribute is replaced.
The
Even if your session attribute implements |