struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hubert Rabago <jakartau...@yahoo.com>
Subject Re: forward vs redirect ?
Date Mon, 01 Dec 2003 23:40:08 GMT

If you define double submissions as the user clicking submit twice, then no,
redirect doesn't save you from that.  You should use transactional tokens
(assuming your app design/specs allow you to).

If your mappings are like this:

<action path="/displayItem" type="MyDisplayAction">
    <forward name="success" path="displayItem.jsp"/>
</action>
<action path="/submitToThisAction" type="MyProcessingAction" 
    input="..." name="...">
    <forward name="success" path="displayItem.jsp"/>
</action>

then when the form gets submitted, the URL on the browser remains
"/submitToThisAction.do" and the resulting page is the one which should not be
bookmarked.  Also, this is the case where the controller gets bypassed because
whatever code MyDisplayAction needs to run before showing "displayItem.jsp"
doesn't get executed. 

If the user refreshes this page, the form gets resubmitted.  If you use
transactional tokens, your "MyProcessingAction" will know to ignore that request,
but it still gets triggered, and "MyDisplayAction" still gets skipped.



If you change the <forward> to this:

<action path="/submitToThisAction" type="MyProcessingAction" input="..."
name="...">
    <forward name="success" path="displayItem.do" redirect="true"/>
</action>

then the browser will send a separate HTTP request for "displayItem.do" which
calls the correct controller and displays your data.
If the user refreshes the resulting page, "MyProcesssingAction" gets skipped
entirely.


Transaction tokens and using redirect solve different problems.  Using one does
not fully help you solve the issues solved by the other.

hth,
Hubert


--- Juan Alvarado <juan110470@yahoo.com> wrote:
> I know every situation is different depending on the
> environment you are in.
> 
> However, the use of redirect to prevent double form
> submissions is not an appropriate solution to that
> problem. I prefer to use the built in mechanism in
> struts (transactional tokens) to solve this problem
> for me. This way I can still use the forwarding
> mechanism and maintain my application within the
> confines of an MVC architecture. If you redirect and
> the user bookmarks that page, then anytime the user
> goes to that page, he/she will bypass your controller
> layer (action) where you could do any kind of
> initializations you will need for your users.
> 
> In my case I am stuck with redirects because of some
> issues with virtual hosting. In this case there is no choice.
> 
> __________________________________
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now
> http://companion.yahoo.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message