• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with servlet listeners

 
Gorby Green
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not Tomcat specific.
Moving to Servlets.
 
Gorby Green
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • 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());
}
}
 
dema rogatkin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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:
javax.servlet.http.HttpSessionEvent)" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSessionListener.html#sessionDestroyed(javax.servlet.http.HttpSessionEvent)



From:
javax.servlet.http.HttpSessionEvent)" target="_blank" rel="nofollow">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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
I worked with the wrong version.
Thanks for all help.
/Gorby
 
Antonio Giovanni
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic