What is HttpSessionBindingListener ?

If you have an attribute class(a class for an object that will be stored as an attribute) and you want the objects of this type to be notified when they are bound to or removed from a session.
HttpSessionBindingListener exists so that the attribute itself can find out when it has been added or removed from the session.

Public class Emp implements HttpSessionBindingListener{
Private String name;
Private String city;
Emp(String name,String city){this.name=name;this.city=city;}
Public String getname(){return name;}
Public String getcity(){return city;}
Public void valueBound(HttpSessionBindingEvent event){
//code to run now that I know I am in a session}
Public void valueUnbound(HttpSessionBindingEvent event){
//code to run now that I know I am no longer in the session}}

Here Emp is itself a listener.
Remember this listener is not mapped in web.xml.

No comments:

Post a Comment