aspose file tools
The moose likes Servlets and the fly likes When HttpSessionAttributeListener and HttpSessionBindingListener methods are called? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "When HttpSessionAttributeListener and HttpSessionBindingListener methods are called?" Watch "When HttpSessionAttributeListener and HttpSessionBindingListener methods are called?" New topic
Author

When HttpSessionAttributeListener and HttpSessionBindingListener methods are called?

Krishna D. Bhat
Greenhorn

Joined: Feb 25, 2007
Posts: 10
Hi Friend,

I am trying to understand usage of the listeners. But I am kind of stuck in at usage of the HttpSessionAttributeListener and HttpSessionBindingListener. I have written a ServletContextListener:


To set the Dog context object which implements HttpSessionAttributeListener & HttpSessionBindingListener:


And written a Servlet which gets the Dog object and prints.


As you can see here I also overwrite, remove and re-assign the Dog object but I don't see any trace!!! I can only see the Constructor calls ...

my web.xml is:


This is the example given in the Head First Servlet & JSP 2nd Edition (Page 183)!!!

Can you please let me know, what should I need to do to trigger those methods??

Thanks,
Krishna

This message was edited 1 time. Last update was at by Bear Bibeault



SCJP: 96% SCWCD: studying
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32421
Here's a little hint: You're using a HttpSessionAttributeListener and a HttpSessionBindingListener. Maybe the servlet API contains some other class that is better suited for handling context attributes?

This message was edited 1 time. Last update was at by Ulf Dittmer



Android appsImageJ pluginsJava web charts
Krishna D. Bhat
Greenhorn

Joined: Feb 25, 2007
Posts: 10
Ulf Dittmer wrote:Maybe the servlet API contains some other class that is better suited for handling context attributes?

I am using the Apache Tomcat 6.0, are you aware of any other attribute handler here?? Still I think it should be supported as per Java Servlet Spec.

Please let me also know if I am using these interfaces wrongly??

Thanks,
Krishna
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 48844

Krishna D. Bhat wrote:Still I think it should be supported as per Java Servlet Spec

How so? Where in the Servlet spec does it say that session listeners will be called when you are doing nothing that has anything at all to do with sessions?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 639
Krishna D. Bhat wrote:I am using the Apache Tomcat 6.0, are you aware of any other attribute handler here?? Still I think it should be supported as per Java Servlet Spec.

Please let me also know if I am using these interfaces wrongly??

Thanks,
Krishna


Krishna,

Please read again Ulf's post. He was giving you a really big hint. Look at the parts of the message he emboldened
Krishna D. Bhat
Greenhorn

Joined: Feb 25, 2007
Posts: 10
Bear Bibeault wrote:How so? Where in the Servlet spec does it say that session listeners will be called when you are doing nothing that has anything at all to do with sessions?

Hmmm Yes!!! now I got it!!! I was confused the Session attribute listeners to work when attribute in the Context is changed.

Thanks Bear Bibeault!!! I will try doing in the HttpSession.

Thanks,
Krishna
 
 
subject: When HttpSessionAttributeListener and HttpSessionBindingListener methods are called?
 
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture