Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect or forward

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?

like image 248
dublintech Avatar asked Mar 27 '12 08:03

dublintech


2 Answers

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.

like image 84
Jasonw Avatar answered Sep 30 '22 04:09

Jasonw


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.

like image 24
Tito Avatar answered Sep 30 '22 04:09

Tito