Its to be implemented by objects that you add to a session if you want the object itself to be aware that it is being added or removed from a session.
For example, you might have a User object that you bind to the session when a User logs in. You could make it the responsibility of the User object itself to log that event, which it could do in the valueBound method. Likewise, when the object is removed from the session, it could log this too. Notice that this gives you an opportunity to do something when a session times-out, which is hard to get a hook into otherwise.
HttpSessionBindingListener exist so that the attribute itself can find out when it has been added to or removed from a session. Specifically used to synchronize the contents of bean and database.
When setAttribute(String name, Object value) is executed the container calls HttpSessionBindingListener.valueBound, to notify object is bound to session,If an object was already bound to this session of this name that implements HttpSessionBindingListener, its HttpSessionBindingListener.valueUnbound method is called.
Hey Dilshaan !! Just curious, Do you really have the Head First JSP and Servlets Book or are you looking at the specs and asking the questions here. Get the book man !! Its much easier to learn from that. Whatever questions you are asking are very simple in the book and I'm sure most of us here would feel like nutcases trying to answer your questions. Even though the Java Ranch blood (with me) is nice people all the way !! :-)
SCJP, SCWCD, SCBCD, IBM XML, IBM OOAD, SCEA 5, ITAC - Distinguished IT Architect.
Joined: Apr 22, 2006
Aswanth Sorry for the inconvinience I have the book but. But some of the things are confusing without examples.
never be embarrassed about asking questons. that's what the forums are for. what is perfectly clear to one person in a book may be quite murky to another. when you ask a question you might very well be asking that others have wondered about as well.
httpsessionbindinglistener has always seemed a bit odd to me and i'm sure it has to some other people as well. so i'm not surprised that you asked the question, and i think you got some informative answers.
so keep asking questions...
Joined: Apr 22, 2006
Thank you Ken for your opinion. Yesterday I got upset after I saw that. But they must understand that everybody doesn't have the same mental ability.