• Post Reply Bookmark Topic Watch Topic
  • New Topic

Session Listener

Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question from HF book chapter 6 coffee cram exam

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 given is A and C

But what I think is E should also be notified

the explanation/reason given for Option E which is not correct : removing an attribute isn’t tightly associated with a session timeout

May I know what is the meaning of "isn’t tightly associated with " ??

Ankit Garg
Posts: 9597
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the answer is simple. HttpSessionAttributeListeners are not notified when a session is about to timeout. HttpSessionListeners are made only to be notified about session state. And if you check the API Docs of HttpSessionBindingListener, then this is mentioned specifically there

Causes an object to be notified when it is bound to or unbound from a session. The object is notified by an HttpSessionBindingEvent object. This may be as a result of a servlet programmer explicitly unbinding an attribute from a session, due to a session being invalidated, or due to a session timing out.

This must be mentioned in the servlet specification too but I've not read that so can't tell you the exact section...
get schwifty. tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!