GeeCON Prague 2014*
The moose likes Struts and the fly likes Session.invalidate and Response.redirect from within the interceptor not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Session.invalidate and Response.redirect from within the interceptor not working" Watch "Session.invalidate and Response.redirect from within the interceptor not working" New topic
Author

Session.invalidate and Response.redirect from within the interceptor not working

Sandeep Murthy
Ranch Hand

Joined: Oct 05, 2005
Posts: 34
I'm having a Struts2 interceptor.

Within the interceptor, I'm invalidating the Session, and then redirecting to an URL, outside the application.
Instead of going to the URL, I'm getting the following Exception in the browser - "Session already invalidated".

From the StackTrace, I can see that the exception is being generated from the FilterDispatcher.java, as it is trying to access the session.
I'm not understanding why the FilterDispatcher is coming into picture after being redirected to an URL outside of the application. (For testing purpose, I am redirected to www.google.com)

please see below the code and full StackTrace. Kindly have a look at it and let me know if I'm doing something wrong.
Many thanks in advance for the help.
Code:



Full Stack Trace:


SCJP 1.4
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Session already invalidated, Means the session object is already terminated by server. what is the session timeout configured in web.xml file.


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
Sandeep Murthy
Ranch Hand

Joined: Oct 05, 2005
Posts: 34
@Mohan Rao: There is no session-timeout defined in web.xml. Hence it will take the default 30 mins.

If you go through my interceptor code above, I am invalidating the session, as it is my requirement. But the problem is, I am getting the error, instead of the response.sendRedirect() working properly.
If I comment out the session.invalidate() code above, the redirect works perfectly.
Sandeep Murthy
Ranch Hand

Joined: Oct 05, 2005
Posts: 34
Found a solution for my own problem:

It looks like the struts2 framework still needs the Session to successfully redirect to a different URL from within the Interceptor. (Although I don't know why, or is it a bug or a feature).

So, it seems we cannot invalidate the session from within the Interceptor and then redirect the response.
Instead, from the interceptor, I am forwarding to a JSP, and doing the "session invalidate and response.redirect()" thing from within the JSP.

Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Here you are checking, if the user is idle for more than 8 hrs then invalidate the session but as you mentioned server is going to invalidate the session after 30min, then how do you invalidate the session?
 
GeeCON Prague 2014
 
subject: Session.invalidate and Response.redirect from within the interceptor not working