About Head First SCWCD Question
Here's the 15th question of Chapter 5:
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 correct answer is A and C. The explanation with option E is "Option E: Removing an attribute isnt tightly associated with a session timeout"
Now my problem 开发者_运维百科is this.. when i tried to invalidate or set an expiry duration of 0 seconds the options A C E are triggered. So calling all WCD certified, can you guys explain why option E is incorrect?
I think their question is poorly worded. You can "ask the container to notify your application whenever a session is about to timeout" from any of those places, or none of them.
A better phrasing might be:
Which interface(s) should you implement if you want to be notified whenever a session is about to timeout?
But in any case, the JavaDoc is always a good place to start. You wouldn't use attributeRemoved()
to track session timeouts because a session can have an arbitrary number of attributes, any one of which can be removed at any time, regardless of whether or not the session is expiring. So the fact that an attribute has been removed is not a reliable indicator that the session has timed out. As the official explanation says, "removing an attribute isn't tightly associated with a session timeout". I would argue that it's not even loosely associated with a session timeout.
Disclaimer: I'm not any kind of certified. I just do this sort of thing for a living.
精彩评论