• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot get HttpSessionBindingListener method valueBound to trigger

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm reading the excellent 'Head First Servlets and JSP' book, and am trying to extend one class to implement HttpSessionBindingListener, but it's not working.

Here is the simple Dog class that I extended:



Here is the Context listener that sets the dog instance as a context attribute:

And here is the Servlet:


But for some reason, the valueBound method never seems to be triggered.

ANy clues why this is the case?

Kind regards,

Tony.
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A HttpSessionBindingListener causes an object to be notified when it is bound to or unbound from a session..

1. You dont need a ServletContextListener - binding the object to the context wouldnt fire the HttpSessionBindingEvent.

2. Change the code in your servlet to attach the 'dog' object to a HttpSession



Hope that helps,
Ram.
 
Tony Bateman
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Helps a lot! Thanks :-)

Kind regards,

Tony.
 
Tony Bateman
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK....went back this evening, re-read the section of the book, recoded my classes and still doesn't work.

Can somebody have a look:

Dog class (which now implements HttpSessionBindingListener):



And the servlet:


Still not triggering the Dogs valueBound or valueUnbound methods.

Can somebody please tell me why?

Kind regards,

Tony.
 
Tony Bateman
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fixed it. Got it working thanks.

- Tony.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess that when the object is atached to the session or dismissed from the session..here by session i mean the user session (request.getSession())
this works...but in your case your are setting it to the ServletContext.

i have not tested this ...so , kindly let me know whether it works for you.

e-mail: rahul.rec.dgp@gmail.com

cheers!
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul, this is a plain old Java class (Not a servlet). HtpSessionBindingListener causes an object to be notified when it is bound to or unbound from a session. And this happens when the object is added, replaced or removed from the session. As in SetAttribute, removeAttribute, replaceAttribute.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic