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!