Session binding listener

Another form to check the attributes of a session is through session binding. We can extend any object that will get in the session as an attribute and check it each time it is managed. The javax.servlet.http.HttpSessionBindingListener interface provides two methods for the object:

  • The valueBound method starts when the MyAttribute object is taken through the session.setAttribute(...) method
  • The valueUnbound starts when the session.removeAttribute(...) method is executed on the MyAttribute object

Here a sample of Session binding listener implementation:

public class MyAttribute implements HttpSessionBindingListener {
private static final Logger logger = getLogger(MyAttribute.class.getName());
@Override
public void valueBound(HttpSessionBindingEvent event) {
logger.info("MyAttribute.valueBound: " + event.getName());
}
@Override
public void valueUnbound(HttpSessionBindingEvent event) {
logger.info("MyAttribute.valueUnbound: " + event.getName());
}
}
The class implementing the HttpSessionBindingListener cannot have the WebListener annotation because it is not really a listener but only an object to intercept.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.244.216