• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionBindingListener - unbounding value, session timeout

 
Piotr Nowicki
Ranch Hand
Posts: 610
IntelliJ IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2173
57
Android Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pedro,

You got it right!

Regards,
Frits
 
Piotr Nowicki
Ranch Hand
Posts: 610
IntelliJ IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rancher!
:-)))
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. ???
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2173
57
Android Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please don't ask the same question in two different threads,

look here

Regards,
Frits
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic