wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HttpSessionBindingListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HttpSessionBindingListener" Watch "HttpSessionBindingListener" New topic
Author

HttpSessionBindingListener

Srinivasan Rengan
Ranch Hand

Joined: Nov 07, 2004
Posts: 122
Ranchers,
Can some one tell me, as to how HttpSessionBindingListener works. When does the valueBound() or valueUnbound() gets fired. I understand that valueBound is called whenever an object of the particular type is added to the session and valueUnbound is called when the object is removed. But, when I tried to do the same, I got a different kind of behaviour.

My code was something like this:


public void doGet(request,reponse) {
.......
.....
MyClass obj = new MyClass();
session.setAttribute("mine1",obj);
session.setAttribute("mine1",obj);
session.setAttribute("mine1",new MyClass());

}

what should actually happen in the above case, if the valueBound and valueUnbound methods will have a console printing as follows:

public void valueBound(HttpSessionBindingEvent event) {
System.out.println("Bound=="+event.getName());
}

public void valueUnbound(HttpSessionBindingEvent event) {
System.out.println("Unbound=="+event.getName());
}

Awaiting answers from you friends!!
Thanks a lot in advance!!
Srini



SCJP, SCWCD, SCBCD (EJB 2.x and EJB 3), OCA, SCDJWS
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Srini,

here is an explanation from HFSJ:


originally from HFSJ p. 254

If an attribute class (like the Dog class here) implements the HttpSessionBindingListener, the Container calls the event-handling callbacks(valueBound() and valueUnbound()) when an instance of this class is added to or removed from a session.


In your case, your attribute class is MyClass instead of Dog. So I suppose your MyClass looks similar to:



Regards,
Darya


SCJP, SCJD, SCWCD, SCBCD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HttpSessionBindingListener
 
Similar Threads
jdiscuss question
HttpSessionBindingListener
is this a bug?
jsp-servletListener
Session Listeners Questions