• 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

problem with servlet listeners

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I have some problem with servlet listerner.
When a user exit I want to save the user object stored in HTTPSession.
And I have read that sessionDestroyed is called when the session realy is destroyed.
But i want to save the context in user object just before session is destroyed.

Is there any chance to do that with servlet listeners?
Thanks in advance!
 
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
Under Servlets 2.4 (Tomcat 5) the listener is called just before the session is destroyed.
[ January 19, 2006: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not Tomcat specific.
Moving to Servlets.
 
Gorby Green
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I would like to save MyObject before session is destroyed.
But sessionDestroyed() is called just after the session is destroyed.
Is there any listener where i can save MyObject before it is removed from session?

public class HttpListner implements HttpSessionListener{

public void sessionCreated(HttpSessionEvent se) {
System.out.println("HttpListner sessionCreated");
}

public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = arg0.getSession();
MyObject object = (MyObject) session.getAttribute("myObject");
System.out.println("name:" + myObject.getName());
}
}
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like a bug in a servlet container you are using:
For example I use session listener for saving user data, like:

I use a servlet container different than Tomcat.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you started this thread in Tomcat, I'll assume that that's your container.
What version of Tomcat are you using?

As Bear mentioned, Servlet Spec 2.4 requires that the sessionDestroyed method be called before the session expires. This was not the case in earlier servlet spec releases.

From:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSessionListener.html#sessionDestroyed(javax.servlet.http.HttpSessionEvent)



From:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpSessionListener.html#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
 
Gorby Green
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
I worked with the wrong version.
Thanks for all help.
/Gorby
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok,.. is there any work around way, of doing what you do in

public void sessionDestroyed(HttpSessionEvent se) of
HttpSessionListener from J2ee 1.4 specs

in J2ee 1.3 specs.
because in j2ee 1.3 the session is invalidated before HttpSessionListener is invoked. I really do not understand the need for having sessionDestroyed(HttpSessionEvent se) in J2ee 1.3

Thanks for the ideas
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Antonio Giovanni:
Ok,.. is there any work around way, of doing what you do in

public void sessionDestroyed(HttpSessionEvent se) of
HttpSessionListener from J2ee 1.4 specs

in J2ee 1.3 specs.




I guess it would depend on what you want to use it to do.
 
reply
    Bookmark Topic Watch Topic
  • New Topic