When an application stores an object in or removes an object from a session, the session checks whether the object implements HttpSessionBindingListener. If it does, the servlet notifies the object that it has been bound to or unbound from the session. Notifications are sent after the binding methods complete. For session that are invalidated or expire, notifications are sent after the session has been invalidatd or expired.
The above is basically an excerpt from the description of javax.serlet.http.HttpSession.
My doubt is in the portion in bold above, meaning i dont understand which notifications are they talking about? Is it the notifiaction which will be sent to the HttpSessionAttributeListener, which is registered in the web.xml; because, if the attributes implement the HttpSessionBindingListener, as soon as the session invalidates, first they would be notified by the container. Is it that immediately after that notification will be sent to the HttpSessionAttributeListeners???
Thanks, Amit [ June 05, 2006: Message edited by: Amit Das ]
Scenario: you have configured, in web.xml, an HttpSessionAttributeListener. You also have a class which implements HttpSessionBindingListener. You create an object of the class which has implemented HttpSessionBindingListener. On setting it as a session scoped attribute, an HttpSessionBindingEvent occurs and a notification will be generated and sent to both listeners as they both receive HttpSessionBindingEvent notifications. The object which implemented HttpSessionBindingListener will be notified first. The HttpSessionAttributeListener will be notified second. If the session is invalidated/expires the HttpSessionBindingListener again is notified first and then the HttpSessionAttributeListener. Pretty sure I remembered this correctly, but may I suggest you code up a scenario throwing some println statements to the log or console.
It's a pleasure to see superheros taking such an interest in science. And this tiny ad: