You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by fea jabi <zy...@hotmail.com> on 2006/02/09 16:59:40 UTC

calling DispatchAction when clicked Refresh on Browser

I my JSP I am having a button "Add", which adds a row to the table when 
clicked and this code is in DispatchAction. i.e adding one more object to my 
table List.

Everything works fine.

When I click on the Refresh on the toolbar of the browser, I am seeing that 
it tries to execute this Add method, and adding one more row.

why is that? How to prevent the same?

Thanks.

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfeeŽ 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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


Re: calling DispatchAction when clicked Refresh on Browser

Posted by Michael Jouravlev <jm...@gmail.com>.
On 2/9/06, fea jabi <zy...@hotmail.com> wrote:
> I my JSP I am having a button "Add", which adds a row to the table when
> clicked and this code is in DispatchAction. i.e adding one more object to my
> table List.
>
> Everything works fine.
>
> When I click on the Refresh on the toolbar of the browser, I am seeing that
> it tries to execute this Add method, and adding one more row.
>
> why is that? How to prevent the same?

Because it is not "refresh", it is "reload". Browser cannot refresh a
page, but it can resend the request that generated this page. Thus,
browser resends your last POST request which calls your
DispatchAction.

Your choices:
* to use token. Browser will still resend a request, but you can check
whether it is a resubmission, thus you can prevent calling your
method. This will be more complex for DispatchAction, you need to
check token before your handler is called.

* to use redirection to your result page. See
http://www.theserverside.com/articles/article.tss?l=RedirectAfterPost
and http://www.theserverside.com/articles/article.tss?l=RedirectAfterPost2
for possible implementation.

Michael.

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


Re: calling DispatchAction when clicked Refresh on Browser

Posted by fea jabi <zy...@hotmail.com>.
Thank you all for the responses. I'll take a look at it.


>From: Emmanouil Batsis <Em...@eurodyn.com>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: Struts Users Mailing List <us...@struts.apache.org>
>Subject: Re: calling DispatchAction when clicked Refresh on Browser
>Date: Thu, 09 Feb 2006 18:26:47 +0200
>
>
>Hello Fea,
>
>fea jabi wrote:
>
>>When I click on the Refresh on the toolbar of the browser, I am seeing 
>>that it tries to execute this Add method, and adding one more row.
>>
>>why is that? How to prevent the same?
>
>
>In general it is a good practice to redirect instead of forwarding to the 
>view after making database changes. This is called the "Redirect after 
>post" pattern (well, if i can call it that), see [1] .
>
>[1] http://www.theserverside.com/articles/article.tss?l=RedirectAfterPost
>
>hth
>
>Manos
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


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


Re: calling DispatchAction when clicked Refresh on Browser

Posted by Emmanouil Batsis <Em...@eurodyn.com>.
Hello Fea,

fea jabi wrote:

> When I click on the Refresh on the toolbar of the browser, I am seeing 
> that it tries to execute this Add method, and adding one more row.
>
> why is that? How to prevent the same?


In general it is a good practice to redirect instead of forwarding to 
the view after making database changes. This is called the "Redirect 
after post" pattern (well, if i can call it that), see [1] .

[1] http://www.theserverside.com/articles/article.tss?l=RedirectAfterPost

hth

Manos

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