hadescz
hadescz

Reputation: 59

Post/Redirect/Get on Struts 1

I have a Struts 1 web application and I would like to implement post/redirect/get in order to force a redirect when the user press back/forward button on the browser. The main problem is that we want to implement a session time out. We are redirecting to a "sessionExpired" page when the session has expired, but we want to hidde the information of the previous page if the user clicks back on the browser. I have already add the code to remove the cache on the actions:

response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");
response.setHeader("Pragma", "no-cache");

But that will throw a "Not found page on the cache" of the browser, and we want to run something that redirects to a page instead of the "no cache" page. That's why I'm trying to implement PRG.

Upvotes: 3

Views: 5059

Answers (2)

JDGuide
JDGuide

Reputation: 6525

Set these lines on your View( Jsp page).Top of the page after your directive tags.

    response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache"); 

And use redirect="true" in struts.

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691645

The Post/Redirect/Get pattern doesn't consist in forcing a redirect when the user presses the Back button. It consists in sending a redirect after a successful POST request.

In Struts 1, define the forward with redirect="true", and Struts will send a redirect if you return this forward:

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

Upvotes: 2

Related Questions