• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpSessionBindingListener - unbounding value, session timeout

 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pedro,

You got it right!

Regards,
Frits
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rancher!
:-)))
 
Ranch Hand
Posts: 211
Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please don't ask the same question in two different threads,

look here

Regards,
Frits
 
reply
    Bookmark Topic Watch Topic
  • New Topic