Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Quest About Session Manger

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please note the question is asking you this:

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 ]
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And BTW, HttpSessionActivationListener is NOT configured in the deployment descriptor.
 
GuanXing Fung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for Kyle Tang and Tracy Woo !
But I still have a puzzle now.

HttpSessionListener and HttpSessionAttributeListener is defined in <listener> in your web.xml. They are "application-wide", they manage all the session in your web-application!


When will the attribute that implemant the HttpSesionAttributeListener work and how does it work to manage all the session in webapplication
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic