Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

HttpSessionBindingListener - unbounding value, session timeout  RSS feed

 
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • 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!
 
Creator of Enthuware JWS+ V6
Bartender
Posts: 3121
259
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pedro,

You got it right!

Regards,
Frits
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rancher!
:-)))
 
Ranch Hand
Posts: 209
Java Tomcat Server
  • 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
Bartender
Posts: 3121
259
Android Chrome Eclipse IDE
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!