• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When HttpSessionAttributeListener and HttpSessionBindingListener methods are called?

 
Krishna D. Bhat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Krishna D. Bhat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic