wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Quest About Session Manger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Quest About Session Manger" Watch "Quest About Session Manger" New topic
Author

Quest About Session Manger

GuanXing Fung
Greenhorn

Joined: Sep 17, 2002
Posts: 5
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 ]

scjp2
Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
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 ]

Kyle Tang<br />SCJP 91<br />SCWCD 96<br />SCBCD 95
Tracy Woo
Ranch Hand

Joined: Jul 23, 2002
Posts: 113
And BTW, HttpSessionActivationListener is NOT configured in the deployment descriptor.
GuanXing Fung
Greenhorn

Joined: Sep 17, 2002
Posts: 5
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
Maha Annadurai
Ranch Hand

Joined: Oct 27, 2002
Posts: 87
"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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Quest About Session Manger
 
Similar Threads
Listener statement doubt
Doubt in Session Related Question -
need help on question on sessions
Doubt in sessions from Hanumant Deskhmukh book
session