You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Jones, Dean" <dj...@refco.com> on 2000/09/26 20:36:06 UTC
Forward vs. Redirect
I wanted to get some particular behavior in processing my forms, namely,
that the form would be submitted, processed by an action, and the request
REDIRECTED to a new view. I was attempting to work around dangerous
behavior
with forms, namely, when a form is submitted and a new view is FORWARDED, a
refresh will re-post the form. This is bad if the form just submitted a
trade
of a few million dollars worth of Corn Futures or something. Now, most of
our orders have a confirm page, but someone, someday, will mess this up.
REDIRECTING to a new view takes care of this, the refresh buttion will just
re-load the page. In an attampt to make this work, I changed the
``forward''
parameter of the ActionServlet to
org.apache.struts.action.RedirectingActionForward.
This almost works, as my actions have paths such as
/trading/futures_order.jsp,
and a ForwardingActionForward used a RequestDispatcher.forward() to do the
work,
and will append the web-app's configured path to the front, and everything
is
cool. A redirect uses response.sendRedirect(), which will not map the
web-app's
path in front of the request. Well, it will if you use a relative path,
if I
am reading the Servlet 2.2 spec correctly. So, if I change these to
relative
paths, then this works fine, but breaks all my other ``forward'' entries
in
action.xml, as they all have to be relative paths, and the question is
relative
to what, since I have no idea where they will be used from in the site.
The
idea was to have them be absolute from the web-app's root, not the site
root, right ???
Does anyone understand my problem, or offer any workarounds ???
Dean S Jones
Re: Forward vs. Redirect
Posted by Mike La Budde <mi...@irista.com>.
Dean:
You might be able to add an "extra" action between the existing
ProcessFuturesOrderAction.do (or whatever it's called) and
FuturesOrderPlaced.jsp. If your current flow is:
EditFuturesOrderAction.do -> FuturesOrder.jsp ->
ProcessFuturesOrderAction.do -> FuturesOrderPlaced.jsp
Then, what I am suggesting is that using this flow:
EditFuturesOrderAction.do -> FuturesOrder.jsp ->
ProcessFuturesOrderAction.do -> DisplayFuturesOrderPlaced.do ->
FuturesOrderPlaced.jsp
Would accomplish what you want (i.e. refreshing the final/resulting page
will not resubmit the order). You just need to modify your action.xml file
(or struts-config.xml) slightly to accomplish this and you could still
using forwarding (rather than redirection) if that is better for you.
Just a suggestion; hope I made it clear enough. (and I hope it works for you!)
Mike
(PS: I left out the ConfirmFuturesOrder stuff for simplicity.)
At 09/27/2000 05:33 PM +0000, Mike Papper wrote:
>I had the same issues. Note that you can do:
>
><forward name="blah" path="..." redirect="true"/>
>when defining your forward/redirect tag. Then you need to set the path
>if it is relative it is relative to the current page...and because of
>this I always put the "context's path" as a prefix to where I want to
>redirect. To do this I created a method that does this automatically for
>me, thus I set the path in the forward tag to /.../... where the /
>represents the "root" of my site. Then my code that does the redirecting
>preprends this path with the context's path.
>
>Its a stupid setup the diff. Between forward and redirect.
>
>Mike Papper
>
>Original Message dated 9/26/2000, 11:36:06 AM
>Author: "Jones, Dean" <dj...@refco.com>
>Re: Forward vs. Redirect:
>
>
>
>I wanted to get some particular behavior in processing my forms, namely,
>that the form would be submitted, processed by an action, and the
>request
>REDIRECTED to a new view. I was attempting to work around dangerous
>behavior
>with forms, namely, when a form is submitted and a new view is
>FORWARDED, a
>refresh will re-post the form. This is bad if the form just submitted a
>trade
>of a few million dollars worth of Corn Futures or something. Now, most
>of
>our orders have a confirm page, but someone, someday, will mess this
>up.
>REDIRECTING to a new view takes care of this, the refresh buttion will
>just
>re-load the page. In an attampt to make this work, I changed the
>``forward''
>parameter of the ActionServlet to
>org.apache.struts.action.RedirectingActionForward.
>This almost works, as my actions have paths such as
>/trading/futures_order.jsp,
>and a ForwardingActionForward used a RequestDispatcher.forward() to do
>the work,
>and will append the web-app's configured path to the front, and
>everything is
>cool. A redirect uses response.sendRedirect(), which will not map the
>web-app's
>path in front of the request. Well, it will if you use a relative path,
> if I
>am reading the Servlet 2.2 spec correctly. So, if I change these to
>relative
>paths, then this works fine, but breaks all my other ``forward''
>entries in
>action.xml, as they all have to be relative paths, and the question is
>relative
>to what, since I have no idea where they will be used from in the site.
>The
>idea was to have them be absolute from the web-app's root, not the site
>root, right ???
>Does anyone understand my problem, or offer any workarounds ???
>Dean S Jones
Re: Forward vs. Redirect
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Jones, Dean" wrote:
>
>
> I wanted to get some particular behavior in processing my forms,
> namely,
> that the form would be submitted, processed by an action, and the
> request
> REDIRECTED to a new view. I was attempting to work around dangerous
> behavior
> with forms, namely, when a form is submitted and a new view is
> FORWARDED, a
> refresh will re-post the form. This is bad if the form just submitted
> a trade
> of a few million dollars worth of Corn Futures or something. Now,
> most of
> our orders have a confirm page, but someone, someday, will mess
> this up.
> REDIRECTING to a new view takes care of this, the refresh buttion
> will just
> re-load the page. In an attampt to make this work, I changed the
> ``forward''
> parameter of the ActionServlet to
> org.apache.struts.action.RedirectingActionForward.
> This almost works, as my actions have paths such as
> /trading/futures_order.jsp,
> and a ForwardingActionForward used a RequestDispatcher.forward() to do
> the work,
> and will append the web-app's configured path to the front, and
> everything is
> cool. A redirect uses response.sendRedirect(), which will not map
> the web-app's
> path in front of the request. Well, it will if you use a relative
> path, if I
> am reading the Servlet 2.2 spec correctly. So, if I change these to
> relative
> paths, then this works fine, but breaks all my other ``forward''
> entries in
> action.xml, as they all have to be relative paths, and the question
> is relative
> to what, since I have no idea where they will be used from in the
> site. The
> idea was to have them be absolute from the web-app's root, not the
> site root, right ???
> Does anyone understand my problem, or offer any workarounds ???
>
> Dean S Jones
Let me see if I understand the problem correctly -- the interpretation
of the "path" attribute of a <forward> element differs depending on
whether the <forward> ultimately does a redirect or a
RequestDispatcher.forward. It would be nice if Struts would take care
of that little detail for us, so we don't have to modify the path every
time we change our mind.
That is a good idea -- what I'd like to do is implement it (in Struts
1.0) as follows:
* If we are doing a RequestDispatcher.forward, there is no
change -- the path is treated as context relative.
* If we are doing a redirect and the path starts with a slash,
have Struts treat this redirect as context relative.
* If we are doing a redirect and the path does not start with
a slash, have Struts use this value unchanged (you might
be redirecting to a different application, possibly on a
different server).
Does that sound right?
Craig
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00): Sun Technical Briefing
Session T06 (24-Oct 14h00-15h00): Migrating Apache JServ
Applications to Tomcat
Re: Forward vs. Redirect
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Jones, Dean" wrote:
>
>
> I wanted to get some particular behavior in processing my forms,
> namely,
> that the form would be submitted, processed by an action, and the
> request
> REDIRECTED to a new view. I was attempting to work around dangerous
> behavior
> with forms, namely, when a form is submitted and a new view is
> FORWARDED, a
> refresh will re-post the form. This is bad if the form just submitted
> a trade
> of a few million dollars worth of Corn Futures or something. Now,
> most of
> our orders have a confirm page, but someone, someday, will mess
> this up.
> REDIRECTING to a new view takes care of this, the refresh buttion
> will just
> re-load the page. In an attampt to make this work, I changed the
> ``forward''
> parameter of the ActionServlet to
> org.apache.struts.action.RedirectingActionForward.
> This almost works, as my actions have paths such as
> /trading/futures_order.jsp,
> and a ForwardingActionForward used a RequestDispatcher.forward() to do
> the work,
> and will append the web-app's configured path to the front, and
> everything is
> cool. A redirect uses response.sendRedirect(), which will not map
> the web-app's
> path in front of the request. Well, it will if you use a relative
> path, if I
> am reading the Servlet 2.2 spec correctly. So, if I change these to
> relative
> paths, then this works fine, but breaks all my other ``forward''
> entries in
> action.xml, as they all have to be relative paths, and the question
> is relative
> to what, since I have no idea where they will be used from in the
> site. The
> idea was to have them be absolute from the web-app's root, not the
> site root, right ???
> Does anyone understand my problem, or offer any workarounds ???
>
> Dean S Jones
Let me see if I understand the problem correctly -- the interpretation
of the "path" attribute of a <forward> element differs depending on
whether the <forward> ultimately does a redirect or a
RequestDispatcher.forward. It would be nice if Struts would take care
of that little detail for us, so we don't have to modify the path every
time we change our mind.
That is a good idea -- what I'd like to do is implement it (in Struts
1.0) as follows:
* If we are doing a RequestDispatcher.forward, there is no
change -- the path is treated as context relative.
* If we are doing a redirect and the path starts with a slash,
have Struts treat this redirect as context relative.
* If we are doing a redirect and the path does not start with
a slash, have Struts use this value unchanged (you might
be redirecting to a different application, possibly on a
different server).
Does that sound right?
Craig
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00): Sun Technical Briefing
Session T06 (24-Oct 14h00-15h00): Migrating Apache JServ
Applications to Tomcat
Re: Forward vs. Redirect
Posted by Mike Papper <mp...@geocities.com>.
I had the same issues. Note that you can do:
<forward name="blah" path="..." redirect="true"/>
when defining your forward/redirect tag. Then you need to set the path
if it is relative it is relative to the current page...and because of
this I always put the "context's path" as a prefix to where I want to
redirect. To do this I created a method that does this automatically for
me, thus I set the path in the forward tag to /.../... where the /
represents the "root" of my site. Then my code that does the redirecting
preprends this path with the context's path.
Its a stupid setup the diff. Between forward and redirect.
Mike Papper
Original Message dated 9/26/2000, 11:36:06 AM
Author: "Jones, Dean" <dj...@refco.com>
Re: Forward vs. Redirect:
I wanted to get some particular behavior in processing my forms, namely,
that the form would be submitted, processed by an action, and the
request
REDIRECTED to a new view. I was attempting to work around dangerous
behavior
with forms, namely, when a form is submitted and a new view is
FORWARDED, a
refresh will re-post the form. This is bad if the form just submitted a
trade
of a few million dollars worth of Corn Futures or something. Now, most
of
our orders have a confirm page, but someone, someday, will mess this
up.
REDIRECTING to a new view takes care of this, the refresh buttion will
just
re-load the page. In an attampt to make this work, I changed the
``forward''
parameter of the ActionServlet to
org.apache.struts.action.RedirectingActionForward.
This almost works, as my actions have paths such as
/trading/futures_order.jsp,
and a ForwardingActionForward used a RequestDispatcher.forward() to do
the work,
and will append the web-app's configured path to the front, and
everything is
cool. A redirect uses response.sendRedirect(), which will not map the
web-app's
path in front of the request. Well, it will if you use a relative path,
if I
am reading the Servlet 2.2 spec correctly. So, if I change these to
relative
paths, then this works fine, but breaks all my other ``forward''
entries in
action.xml, as they all have to be relative paths, and the question is
relative
to what, since I have no idea where they will be used from in the site.
The
idea was to have them be absolute from the web-app's root, not the site
root, right ???
Does anyone understand my problem, or offer any workarounds ???
Dean S Jones