Redirect or forward
Asked Answered
I

3

5

Looking through some legacy code I have in front of me using struts one, I see:

<global-forwards>
     ...
     <forward name="accessDenied" path="/www/jsp/AccessDeniedForm.do" redirect="true" />
</global-forwards>

So it's just a global forward to send to a access denied page. I am curious about the decision to redirect as opposed to forward. What are the advantages and disadvantages of using it?

Iva answered 27/3, 2012 at 8:37 Comment(1)
Answer I was looking for is here... #615016 This thread can be closed as a duplicate. Sorry.Iva
C
5

What are the pro's and con's of using it?

Before discussing pro's and con's of using that forward element with redirect set to true, let's understand what is actually going on with that configuration. When redirect is set to true in the forward element, a redirect instruction should be issued to the user-agent so that a new request is issued for this forward's resource. This link will probably provide detail information that you need.

The default value for redirect is to false, essentially when the forward element is called, it forward to that path specified and that's it. If you are setting redirect to true, take for example, the browser will make another request. So I think with these said, you probably know or have an idea the pro and con if you really want to use it.

Caritta answered 29/3, 2012 at 3:39 Comment(0)
M
2

In redirect, the control can be directed to different servers or even another domain name.The redirect takes a round trip.When a redirect is issued , it is sent back to the client , and redirected URL information is in the header instructing the browser to move to the next URL. This will act as a new request and all the request and response data is lost.

In forward , the forwarding is done from server side , the client browser URL do not change.the data is also not lost.It is just like a browser page refresh. Whatever data posted in the first submit is resubmitted again.So use it with caution.

Both forward and redirect are used in different scenarios ,the global forward should be redirect because it is an error situation.

Redirect is slower as it needs a roundtrip.Forwards are faster.

Magdamagdaia answered 1/4, 2012 at 8:55 Comment(2)
I understand the difference between forward and redirect. I am just looking for the pro's and con's of both approaches and when to use each approach in your struts config.Iva
pros and cons are also explained in the above answer.Magdamagdaia
D
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.

Dibbell answered 2/2, 2016 at 11:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.