Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Question about using HttpSessionBindingListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Question about using HttpSessionBindingListener" Watch "Question about using HttpSessionBindingListener" New topic
Author

Question about using HttpSessionBindingListener

PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212

I cannot think of many practical situations where you would need HttpSessionBindingListener over HttpSessionAttributeListener.

My Question is why do you or in what conditions you would tell a particular object that its value is bounded to the session or unbounded to a session .
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
HttpSessionBindingListener:
You Have one class that you are going to set in session,
If you want to notification when that class bound & unbound to session then that class must implement HttpSessionBindingListener & override 2 methods of that class that are going to call when object is bound & unbound.

HttpSessionAttributeListener:
This is genaral Interface we need to Implement it by our own class override methodes of this interface & decleare our clas in in web.xml.
after that when attrbute is added, removed & replaced pericular method of our class is called accordingly.

Hope this will help you.

Thanks,
Shailesh
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Thanks Shailesh

But my questions still remains the same what is the scenario you would tell a Object that it has been bounded/unbounded to the session??
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Suppose UserInfoObj is class Implementing HttpSessionBindingListener Interface
UserInfoObj have many properties like name, address,phone number etc,
we are storing UserInfoObj into Database table USER_INFO.

Now when this (UserInfoObj) put into session, valueBound method is called(we overrided this method in UserInfoObj)
in this method we can get data from USER_INFO table & store into UserInfoObj.

viseversa

when we remove UserInfoObj from session valueUnbound is called, there we can store data from UserInfoObj into USER_INFO table.

this is practicle situation for HttpSessionBindingListener.


PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Hey Great explanation.

Thanks for your time for answering.

Have a nice day.
 
GeeCON Prague 2014
 
subject: Question about using HttpSessionBindingListener