• 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

How to get HttpSessionListener to respond?

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ran through the example in K&B on using ServletContextListener, that works fine.

But then I tried to use a HttpSessionListener to respond to a user's invoking a servlet by putting an attribute into the session. This listener never gets called.

My listener:



The DD:



The servlet, which I expected would trigger the session listener:



I expected that line 03 above would trigger the session listener to create the attribute. But the output is "Your dog is null". So I am not quite understanding how sessions work.

Am I going about this wrong? Or is this something I should not try at all?
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thomas Kennedy wrote:But the output is "Your dog is null".



Hm. Well, if you didn't get a NullPointerException by referencing d.toString()...what does the SessionDog.toString method look like?
 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, that's it! I was populating the breed member but not the name member. Fixed!
 
reply
    Bookmark Topic Watch Topic
  • New Topic