• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now that I think of it, you should probably look into using Struts tokens, especially if your forms are stored in session scope.
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic