aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HttpSessionBindingListener - unbounding value, session timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HttpSessionBindingListener - unbounding value, session timeout" Watch "HttpSessionBindingListener - unbounding value, session timeout" New topic
Author

HttpSessionBindingListener - unbounding value, session timeout

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Howdy Ranchers!

I am reading B&K&B "Head First Servlets & JSP", chapter 6. I am curious about one exam question, no. 15.


Which method(s) can be used to ask the container to notify your application whenever a session is about to timeout? (Choose all that apply.)

A. HttpSessionListener.sessionDestroyed
B. HttpSessionBindingListener.valueBound
C. HttpSessionBindingListener.valueUnbound
D. HttpSessionBindingEvent.sessionDestroyed
E. HttpSessionAttributeListener.attributeRemoved
F. HttpSessionActivationListener.sessionWillPassivate


The answer is A and C.

I know that there is a disclaimer for option C (as it is a round-about and not a direct solution) but I want to be sure I got it right.

When the session is timed out, the HttpSessionBindingListener.valueUnbound(-) can be used to notify user about it, because:
- session timeout destroys a session (and its all attributes),
- attribute removal will execute valueUnbound method on the perticular attribute.

BUT the other way around is not true. The HttpSessionBindingListener.valueUnbound(-) cannot be used as an indicator of the session timeout.
I mean that user i.e. can programatically do removeAttribute(-) and it will also execute the valueUnbound(-), so it's execution doesn't mean the session has timed out.

Am I getting this right?

Cheers!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1695
    
  25

Hi Pedro,

You got it right!

Regards,
Frits
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Thanks Rancher!
:-)))
Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

Hello,

My understanding is that HttpSessionAttributeListener is implemented by an object that is interested in receiving events from all the sessions belonging to the application, while HttpSessionBindingListener is implemented by the object attributes for the particular session to which they are added or removed.

So,When the session is timed out, the HttpSessionBindingListener.valueUnbound(-) can be used to notify user about it, because:
- session timeout destroys a session (and its all attributes),
- attribute removal will execute valueUnbound method on the perticular attribute.

Now my question Why Can we rely on HttpSessionBindingListeren if it comes to session invalidation and at the same time we can not rely on HttpSessionAttributeListener.attributeRemoved. ???


OCJP-90%,OCPWCD-95%
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1695
    
  25

please don't ask the same question in two different threads,

look here

Regards,
Frits
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HttpSessionBindingListener - unbounding value, session timeout