• 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

session listener

 
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is it not possible to access session attributes in the method sessionDestroyed() of HttpSessionListener by using the session object returned from HttpSessionEvent??
Shankar.
 
Author
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is it not possible to access session attributes in the method sessionDestroyed() of HttpSessionListener by using the session object returned from HttpSessionEvent??


Correct; it is not possible. As discussed in Section 10.7 of More Servlets and JSP, the attributes are removed before sessionDestroyed is called. You need to catch them in the attributeRemoved method of HttpSessionAttributeListener. I haven't found much use for sessionDestroyed other than listeners that merely keep track of the number of active sessions (which is actually helpful to know).
Cheers-
- Marty
 
shankar vembu
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx marty,
i found it the hard way.
actually i had to reset the user login status in the database when session is destroyed. HttpSessionListener did not help me, i modified my design and now using HttpSessionBindingListener. This is clean and works perfect.
Thanx for confirming...
SHankar
 
Ranch Hand
Posts: 686
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I am not agree with Marty,
I am able to trace session attributes in sessionDestroyed method.
-Jignesh
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may depend upon which servlet container and version you are using. Under the Servlet 2.3 specification, the definition of the sessionDestroyed method was:

Notification that a session was invalidated.


under Servlet 2.4:

Notification that a session is about to be invalidated.


So it is perfectly plausible that a 2.3 engine would blow away the session prior to calling sessionDestroyed, while a 2.4 engine will not.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I get the actual session attribute object? I have a servlet that for various reasons needs to open a DB connection with each session, and I want to close those connections as the sessions time out. How do i get the actual Connection object that is the value of my session attribute, so I can call close() on it?
Thanks,
John
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic