Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts 1 not user-friendly with the browser back button: any solutions?

Tags:

java

struts

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)?

like image 455
Amoeba Avatar asked Jan 24 '23 11:01

Amoeba


2 Answers

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.

like image 196
Henning Avatar answered May 08 '23 04:05

Henning


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.

like image 31
blockhead Avatar answered May 08 '23 04:05

blockhead