Announcement Announcement Module
Collapse
No announcement yet.
How to prevent form submits when using back (browser history) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    You can use the Post-Redirect-Get design pattern.

    Comment


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

      Comment


      • #4
        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

        Comment


        • #5
          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.

          Comment


          • #6
            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...

            Comment

            Working...
            X