Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sandeep Murthy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session already invalidated, Means the session object is already terminated by server. what is the session timeout configured in web.xml file.
 
Sandeep Murthy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic