This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes regarding listeners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "regarding listeners" Watch "regarding listeners" New topic
Author

regarding listeners

Nagamalini Pampati
Greenhorn

Joined: Oct 04, 2006
Posts: 20
Hi,
"If servlet context is destroyed all the attributes associated with it will be removed so the attributeRemoved() will be called for those attributes"
Is this statement true?

Thanks in advance,
Malini.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I can't find such a statement in the specification.


[My Blog]
All roads lead to JavaRanch
Nagamalini Pampati
Greenhorn

Joined: Oct 04, 2006
Posts: 20
There's no such statement in the specification but i have that doubt.....
to be more clear....
i have a class ABC implementing ServletContextAttributeListener......so when the context is destroyed will the attributes associated with it are rremoved from the context?if they are removed, is the attributeRemoved() of class ABC called?
Pls help me..
Thanks in advance,
Malini.
Govinda Attal
Greenhorn

Joined: Sep 07, 2006
Posts: 8
Yes, the listeneres will/must be notified.

Imagine your application is just a single part of big enterprise.
due to some reasons(maintennance) you deice to undeploy your application.
And you want release resources that you have acquired or you want to send a message to JMS server or anything....

You can say this can be done in ServletContextListener. But say your app doesnot have any of these listners. Then attribute listeners can help.

It lot depends on how beautifully we design our application.
Nagamalini Pampati
Greenhorn

Joined: Oct 04, 2006
Posts: 20
Thanks a lot Govinda Attal
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I don't know what you base this kind of statement on.
As I said, there's nothing in the spec about this, so you'd better refer to the container's documentation.

I've just tried on Tomcat, and attributeRemoved was not called.
Saurabh Kumar
Ranch Hand

Joined: Aug 21, 2006
Posts: 56
You are right Satou.

I tried on WSAD5.1 and got the similar result as told by you.
Further I tried same logic on Session.

My Conclusion: ServletContextListener and ServletContextAttributeListener interface are not related/dependent on each other, and a call to contextDestroyed() doesn't trigger call to attributeRemoved() method.
Similarly, a call to sessionDestroyed() doesn't trigger attributeRemoved() to be called.

I would be glad if anyone would correct/add to my understanding.

Thanks and regards,
Saurabh
Nagamalini Pampati
Greenhorn

Joined: Oct 04, 2006
Posts: 20
but in HFSJ it is given as calling invalidate() on session object will unbind all session attributes currently stored in the session.doesn't this mean that valueUnbound or attributeRemoved methods are called?
Thanks and Regards,
malini
Saurabh Kumar
Ranch Hand

Joined: Aug 21, 2006
Posts: 56
calling invalidate() unbounds the session attributes and notifies the object implementing HttpSessionBindingListener, and calls valueUnbound(). But invalidate() doesn't trigger attributeRemoved().

Please correct me if wrong.

Thanks and regards,
Saurabh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding listeners
 
Similar Threads
mock question regarding dynamic attribute
Should I write now SCWCD exam??
where are the request parameters declare
Internal DTD & External DTD
Are session attributes really stored in cookie?