wood burning stoves 2.0*
The moose likes Servlets and the fly likes When HttpSessionAttributeListener and HttpSessionBindingListener methods are called? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
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


SCJP: 96% SCWCD: studying
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41877
    
  63
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?


Ping & DNS - my free Android networking tools app
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 ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When HttpSessionAttributeListener and HttpSessionBindingListener methods are called?