Results 1 to 6 of 6

Thread: How to prevent form submits when using back (browser history)

  1. #1
    Join Date
    Apr 2010
    Posts
    14

    Question How to prevent form submits when using back (browser history)

    Hi there

    Im using spring mvc with tiles and jsp. Normally, when users use the back button of the browser, after submitting a form, the form is submitted again.

    How can i prevent this form to be submitted again (and for example show a default page showing a message like 'you cannot submit this right now')?

    Thanks in advance

  2. #2
    Join Date
    Oct 2005
    Location
    Mobile, AL
    Posts
    345

    Default

    You can use the Post-Redirect-Get design pattern.

  3. #3
    Join Date
    Apr 2010
    Posts
    14

    Default

    This sounds fine, but it would still not adress the issue, if the user pressed the back button..

  4. #4
    Join Date
    Apr 2010
    Posts
    14

    Default

    Ok i solved it now with a session variable that i set, when the form is created and removed when its submitted..

    It still sometimes reacts strange but i dont get any double submits anymore..

    Thanks

  5. #5
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    I'm not familiar with what Spring has done with the JSP layer recently, but quite a while ago Struts had implemented a mechanism that addresses this. When the page is rendered, a token value is allocated and the id for that token is rendered in a hidden field in the JSP. When the form is submitted, the action verifies that the token value equals the value submitted from the hidden field, and rejects it if it's not the same. After it makes that check, it removes the allocated token so that a resubmit after a back press will fail the verification.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Quote Originally Posted by ms-sisa View Post
    This sounds fine, but it would still not adress the issue, if the user pressed the back button..
    Post-Redirect-Get is designed/worked-out especially for this usecase... Because due to this the browser doesn't cache the post anymore and hence you can simply press back without resubmitting the form.. I suggest reading a bit more on the topic...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •