You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ron talk <ro...@hotmail.com> on 2001/01/25 17:03:32 UTC

Handling refresh in a web based application

Hi all,

is there anyway to determine whether a repeated http request has been 
generated through a
      - click on the refresh button on a browser
      - through clicking the back button a the browser and re-clicking the 
link/button generating the initial request

I am working on a struts based application in which I must allow the request 
to be completed if it is though going back and re clicking the link, but if 
its a simple refresh, the request is ignored.



_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


Re: Handling refresh in a web based application

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
ron talk wrote:

> Hi all,
>
> is there anyway to determine whether a repeated http request has been
> generated through a
>       - click on the refresh button on a browser
>       - through clicking the back button a the browser and re-clicking the
> link/button generating the initial request
>
> I am working on a struts based application in which I must allow the request
> to be completed if it is though going back and re clicking the link, but if
> its a simple refresh, the request is ignored.
>

There is a capability to detect repeated submits of the same form, using a
"command token" functionality.

In the Struts example application, you will note that EditRegistrationAction
(which sets up the form bean for the registration.jsp page) calls

    saveToken(request);

near the bottom.  This stores a session attribute with a transactional control
token that must be submitted on the next request in order to be valid.  Then, in
the SaveRegistrationAction (which handles the submit), we see:

    if (!isTokenValid(request)) {
        ... deal with the error ...
    }
    resetToken(request);

so that your app can do whatever is appropriate when it detects a resubmit.

No changes to the JSP pages themselves are necessary (the <html:form> tag
automatically creates a hidden variable if needed).  IMHO, transactional control
like this is a "controller" thing (in the model-view-controller paradigm), so
page authors should not have to be concerned with it.

Craig