每当会话即将超时时,可以使用哪种方法要求容器通知您的应用程序?(选择所有适用的方法)
A. HttpSessionListener.sessionDestroyed — 正确
B. HttpSessionBindingListener.valueBound
C. HttpSessionBindingListener.valueUnbound —正确,这是一种迂回,但如果您有一个属性类,这是一种通知超时的方法
D. HttpSessionBindingEvent.sessionDestroyed - 没有这样的方法
E. HttpSessionAttributeListener.attributeRemoved - 删除属性并不紧密关联带有会话超时
F. HttpSessionActivationListener.sessionWillPassivate -- 会话钝化与超时不同
我同意选项 A.
1) 但 C 是值得怀疑的
value unbound 如何与会话超时紧密耦合。它只是属性获取时的回调方法已删除。
2)如果C是正确的,E也应该是正确的。
HttpSessionAttributeListener 只是一个想要知道会话中何时添加、删除或替换任何类型的属性的类。它由任何类实现。
HttpSessionBindingListener 的存在是为了让属性本身能够发现它何时被添加到会话中或从会话中删除,并且属性类必须实现此接口才能实现它。
任何想法...
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 -- correct
B. HttpSessionBindingListener.valueBound
C. HttpSessionBindingListener.valueUnbound -- correct this is kind of round-about but if you have an attribute class this is a way to be informed of a timeout
D. HttpSessionBindingEvent.sessionDestroyed -- no such method
E. HttpSessionAttributeListener.attributeRemoved -- removing an attribute isn’t tightly associated with a session timeout
F. HttpSessionActivationListener.sessionWillPassivate -- session passivation is different than timeout
I agree with option A.
1) But C is doubtful
How can value unbound be tightly coupled with session timeout.It is just the callback method when an attribute gets removed.
2) and if C is correct, E should also be correct.
HttpSessionAttributeListener is just a class that wants to know when any type of attribute has been added, removed, or replaced in a session. It is implemented by any class.
HttpSessionBindingListener exists so that the attribute itself can find out when it has been added to or removed from a session and the attribute class must implement this interface to achieve it.
Any ideas…
发布评论
评论(1)
我对此问题的解决方案是使用 A。请记住,
HttpSessionListener.sessionDestroyed()
在会话失效之前被调用,因此其所有属性都完好无损。我们的应用程序使用带有键“LOGOUT”的会话属性来表示显式注销。因此,您的代码可能看起来像这样:
据我所知,没有标准方法可以从
HttpSession
判断它为何即将失效,并且令人惊讶的是,< code>HttpSessionEvent 对象,描述事件是什么(直到 Java EE 6)。My solution to this problem is to use A. Remember that
HttpSessionListener.sessionDestroyed()
is called before the session is invalidated so all its attributes are intact.Our application uses a session attribute with key
"LOGOUT"
to signify an explicit logout. So your code may look something like this:As far as I can tell there is no standard way to tell from the
HttpSession
why it is about to be invalidated and, amazingly, there is no information in theHttpSessionEvent
object that describes what the event was (this is true up to Java EE 6).