the question is in the SwcdStudyKit,i have puzzle with this.Appreciate for your help! 4. Which of the following methods will be invoked on a session attribute that implements appropriate interfaces when the session is invalidated? (Select one) a sessionDestroyed of HttpSessionListener b attributeRemoved of HttpSessionAttributeListener c valueUnbound of HttpSessionBindingListener d sessionWillPassivate of HttpSessionActivationListener Answer: c Explanation The HttpSessionListener and HttpSessionAttributeListener are con-figured in the deployment descriptor. Therefore, even if a session attribute imple-ments these interfaces, the sessionDestroyed() and attributeRemoved() methods will not be called on that attribute. An HttpSessionActivationListener is also configured in the deployment descriptor, and it is used when a session is passivated or activated. 1 .I coun't understand why a & b is not correct even hough i have look at the Explanation.Anyone can tell me the reason detail? 2. I also wanna to know the difference between the HttpSessionBindingListener and the HttpSessionAttributeListener. [ September 18, 2002: Message edited by: GuanXing Fung ]
Which of the following methods will be invoked on a session attribute
Only HttpSessionBindingListener is good for the answer. It is implemented by session attributes to be notified when itself(the attribute) is added/replace/removed from a session. HttpSessionListener and HttpSessionAttributeListener is defined in <listener> in your web.xml. They are "application-wide", they manage all the session in your web-application! And they are instanticated by your web-container, if you define one in your web.xml, one instance created, if two, then two instance created, etc. Even if your session attribute implements HttpSessionListener or HttpSessionAttributeListener, but you do not define that in web.xml, there is NO HttpSessionListener or HttpSessionAttributeListener instance in your web-application at all! (If you just create an HttpSessionListener instance by your own, it won't work because your web-application does not know at all, it only checks the web.xml) please dig more from Servlet spec. [ September 18, 2002: Message edited by: Kyle Tang ]
"When will the attribute that implemant the HttpSesionAttributeListener work and how does it work to manage all the session in webapplication?" This question is not worded right. Attributes do not implement HttpSessionAttributeListener in order to get notified. We developers , write a separate Java class, make it to implement the HttpSessionAttributeListener , define the fullly qualified class name in <listener> </listener> element in web.xml. This means, the container is in look out for any HttpSessionBindingEvent happening throughout the web application. Whenever we add/replace/remove a session attribute , the container automatically generates an event of type HttpSessionBindingEvent and calls the corresponding methods on all HttpSessionAttributeListeners configured in web.xml. So, basically any add/replace/remove operations of session attributes for ALL sessons in the web application, would notify the listeners in web.xml. If you want to know which session is actually causing this, inside your web.xml's HttpSessionAttributeListener's attributeAddded (HttpSessionBindingEvent event) method, use this code. HttpSession session = event.getSession(); The same concept applies for HttpSessionListeners also. Regards, Maha Anna [ November 30, 2002: Message edited by: Maha Annadurai ]
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!