You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "David M. Karr" <dm...@earthlink.net> on 2002/10/05 20:24:45 UTC

Guidelines for choosing forward or redirect?

I'm looking for something which summarizes the guidelines for when to choose a
"forward" or a "redirect".

Related to this, the two basic issues I'm aware of are:
1. Preserving the request parameters, and request-scope beans.
2. The resulting browser URL field.
3. Redirect takes longer, depending on network load.

Are there any other basic issues related to this?

The first issue pushes you down the "forward" path if you have request
parameters or request-scope beans which you need to preserve from step to step.

The second issue basically asks the question: "What will happen if the user
reloads this page or stores it as a bookmark (and later reloads it)?"

The third issue is relatively clear, but I'm unsure of the relative effects of
that.

-- 
===================================================================
David M. Karr          ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Guidelines for choosing forward or redirect?

Posted by Eddie Bush <ek...@swbell.net>.
David M. Karr wrote:

>I'm looking for something which summarizes the guidelines for when to choose a
>"forward" or a "redirect".
>
>Related to this, the two basic issues I'm aware of are:
>1. Preserving the request parameters, and request-scope beans.
>2. The resulting browser URL field.
>3. Redirect takes longer, depending on network load.
>
>Are there any other basic issues related to this?
>
None that I can think of right off.

>The first issue pushes you down the "forward" path if you have request
>parameters or request-scope beans which you need to preserve from step to step.
>
*nod*

>The second issue basically asks the question: "What will happen if the user
>reloads this page or stores it as a bookmark (and later reloads it)?"
>
Well ... that's a multi-faceted answer, now, isn't it?

The most likely scenario is that you have all of your pages prefaced by 
ForwardAction.  This doesn't do "anything bad" to bookmarking - really, 
the action might as well (for all practical purposes) be the final JSP 
page.  We've simply chosen (for whatever reason) to hide the physical 
pages from the user.

What if there are request parameters?

The browser is going to hang on to those in the bookmark URL, I believe, 
so, say you have a given action that loads content (magazine articles, 
for the sake of discussion) and displays them to the user.  What's the 
impact?  Probably none.  As long as the action has everything it needs 
to reconstruct the request everything should be "peachy".

What if we're in a work-flow?

:-) There could conceivably be issues here, I would think.  Say, for 
instance, a previous stage in the workflow had to set some value kept as 
a hidden field in the form.  Obviously, workflows would be an exception 
here.

So, we want our actions to forward to actual pages - to hide them. 
 Redirects would be appropriate for switching from one "logical page" to 
another (times when you want the URL in the user's browser updated so 
bookmarking can still be done effectively).

>The third issue is relatively clear, but I'm unsure of the relative effects of
>that.
>
Personally, my rule of thumb is:  Is this a "logical page"?  If it is, I 
forward.  If it is not, I redirect.

That's probably an exceedingly poor clearification - hopefully someone 
else will have more "words of wisdom" for you.

Regards,

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>