wood burning stoves 2.0*
The moose likes Struts and the fly likes Best practice for redirecting a page when a Session is expired. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Best practice for redirecting a page when a Session is expired." Watch "Best practice for redirecting a page when a Session is expired." New topic
Author

Best practice for redirecting a page when a Session is expired.

kay lin
Ranch Hand

Joined: May 20, 2004
Posts: 132
Hi all:
I have an ActionForm class, in it, I have a method that populates the drop down from the Session, and I have a validate() to validate the form of course. And if the user enters something wrong, the jsp be page will be reloaded with the error message

Now, my problem is if the Session is timed out, then when the user click the submit button on the form, the JSP page will be reloaded, with the error message. however, any contents in the drop down will be GONE because the session timed out. So for an end user who is not very technical, he/she cannot figure out exactly what went wrong because the error message displayed on the reloade JSP page is not really descriptive of the problems with the drop down.


idealy, I would like my ActionForm class to redirect to a "timeout.jsp" so to speak when the session is timed out, but I can't exactly do this through the validate() method can I?

how should I redirect my page when the session is timed out in Struts? what is the best practice in Struts?


If anyone can lend me a hand on this, I'd be really greatful.


Many thanks
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

There are three options that I know of.
1) Use filters (these are not Struts-specific).
2) Extend RequestProcessor class.
3) Use a superclass action to implement the filtering functionality.

You can search the web for the first two methods. The last one is rather complicated and I don't recommend it for you because you would have to refactor all of your Actions.

The first option is my recommendation because it does not cause you to change any of the already-existing code. A filter would just add another layer.


A good workman is known by his tools.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Now that I think of it, you should probably look into using Struts tokens, especially if your forms are stored in session scope.
Nathan Hook
Ranch Hand

Joined: Jan 10, 2005
Posts: 81
I perfer to use filters here like Marc first suggested. If the session doesn't exist the forward the user to a session expired page.

Best of Luck,

Nate
 
jQuery in Action, 2nd edition
 
subject: Best practice for redirecting a page when a Session is expired.
 
Similar Threads
Problem with redirect after validation
Why is struts calling reset???
RequestDispatching when session is timed out
Specifying new J2EE project - opinions wanted
getSession(false) in Struts' Action class