Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding listeners

 
Nagamalini Pampati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't find such a statement in the specification.
 
Nagamalini Pampati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Govinda Attal
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic