File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Regarding HttpSessionAttributeListener and HttpSessionBindingListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Regarding HttpSessionAttributeListener and HttpSessionBindingListener" Watch "Regarding HttpSessionAttributeListener and HttpSessionBindingListener" New topic

Regarding HttpSessionAttributeListener and HttpSessionBindingListener

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Can anyone please tell about the difference between HttpSessionAttributeListener and HttpSessionBindingListener?

I checked in Head First Servlet Servlet and JSP. It tells

"A plain old HttpSessionAttributeListener is just a class that wants to know when any type of attribute has been added, removed or replaced in a Session. But the HttpSessionBindingListener exist so that the attribute itself can find out what when it has been added to or removed from Session."

Does it mean that HttpSessionAttributeListener tell about any attribute. While HttpSessionBindingListener gives information about attribute itself NOT any other attribute?

Is my understanding right?

Please help me for above concepts.

Thanks Jay.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yes. your understanding is correct. httpSessionBindingListener is for when a particular object wants to be notified when it has been added to the session.

So much trouble in the world -- Bob Marley
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
sorry Ranchers , I cant' find the better opportunity to extend the Thread ,What do you mean by a particular Object as Servlet is a ThreadBased and for every Thread the Object will be unique so my doubt is how this is achieved.

sorry once again for not posting a new topic.

If you want something you never had do something which you had never done
Ankit Garg

Joined: Aug 03, 2008
Posts: 9463

RaviNada the concept is not about a particular Servlet object. It is about a particular object that is added or removed from the Session. Suppose I implement a class which implements the HttpSessionBindingListener interface. Now when I add an object of that class into a session, the valueBound method of my class will be called. Similarly when an object of my class is removed from a session, then the valueUnbound method of my class will be called...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Regarding HttpSessionAttributeListener and HttpSessionBindingListener
It's not a secret anymore!