| Author |
Session.invalidate and Response.redirect from within the interceptor not working
|
Sandeep Murthy
Ranch Hand
Joined: Oct 05, 2005
Posts: 33
|
|
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: 427
|
|
|
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: 33
|
|
@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: 33
|
|
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: 427
|
|
|
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?
|
 |
 |
|
|
subject: Session.invalidate and Response.redirect from within the interceptor not working
|
|
|