4

I have inherited a Java website that uses Struts 1. Currently if the brosers back button is pressed midway through a journey they get a 'Webpage has expired' error.

From my limited understanding, this seems to be a flaw in the design of Struts - every page is a form. Is there anyway to get around the problem, or would the only way be migrating to a different MVC framework (struts2, springMVC)?

Amoeba
  • 631
  • 7
  • 15

2 Answers2

9

This is not a Struts problem, really. Apparently, the guy who built this did not believe in the Post/Redirect/Get pattern, and instead serves up a page directly in response to a form submission.

You can change this behavior by applying redirect="true" to your action forwards:

<action ... >
   <forward name="success"
       contextRelative="true"
       path="/moduleB/index.do"
       redirect="true"/>
</action>

See the Struts user guide for more information.

Henning
  • 16,063
  • 3
  • 51
  • 65
1

I don't think there's anything inherent in struts that does that. It sounds like the previous developer tried to create some kind of wizard. The proper way to do it, would be to store the pending results in the wizard in a session, and do a full redirect after every form submission.

blockhead
  • 9,655
  • 3
  • 43
  • 69
  • Yes its like a wizard, a series of pages 1->2->3->4->5->6 However page 2 relies on the data from form 1. What do you mean by 'a full redirect after every form submission'? – Amoeba Jun 26 '09 at 14:53
  • In most MVC frameworks, as the result of any action, you could either forward to another action or do a redirect. A redirect means that the server tells the browser to physically go to another page. This is what is commonly known as the POST-REDIRECT-GET pattern (http://en.wikipedia.org/wiki/Post/Redirect/Get). For more info on this see this: http://stackoverflow.com/questions/614516/why-use-redirecttrue-in-struts-1-forward I think that will help clear up some things. – blockhead Jun 26 '09 at 15:01