• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about using HttpSessionBindingListener

 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 368
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 368
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 212
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Great explanation.

Thanks for your time for answering.

Have a nice day.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic