Why use 'redirect=true' in struts 1.* forward?
Asked Answered
L

3

24

I've been having some problems with ActionMessages created during execution of an action which didn't display, and I found out that my problems were due to my forwards having redirect=true in struts-config.xml.

Since the default behavior is redirect=false, I've been thinking about which benefits can one have using redirect=true and I couldn't find any answer. Does anyone know when and why redirect=true should be used in action forwards?

Lockout answered 5/3, 2009 at 12:10 Comment(0)
D
38

it prevents the 'double submit problem'

Never show pages in response to POST

Always load pages using GET

Navigate from POST to GET using REDIRECT

more on this here and here

Debutant answered 5/3, 2009 at 12:20 Comment(1)
Seems links URLs have been updated: here and hereWeakly
L
28

Redirect sends a response to the browser that forces the browser to make a new request. From the server point of view, the browser just makes a new request (albeit autmatically). Some characteristics of a redirect:

  • The existing parameters and attributes are disposed, a new request is formed with the parameters you specify in the URL.
  • The new URL is visible in the browser, the user can bookmark it.
  • It takes a trip to the browser and back, so it can be slower.

A forward happens on the server. The browser is not involved in this. Some characteristics of the forward:

  • New parameters are added or overwrite existing parameters. So the existing parameters cannot be removed from the request.
  • Stuff can be added in request context, it will remain available. You can pass information in this way.
  • The URL is not changed in the browser, for the browser the original address remains intact.
  • You can only forward to another URL in the same application.

So it depends on what you want to accomplish. A forward is generally spoken faster. But if the user should be able to bookmark the new location, it is not an option.

Liberati answered 11/3, 2009 at 20:45 Comment(0)
P
0

If you specify redirect="true", Struts uses a client-side redirect [response.sendRedirect()]. The JSP will be invoked by a new browser request, and any data stored in the old request will be lost.

Phalange answered 2/2, 2016 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.