Stop data inserting into a database twice

后端 未结 16 1397
再見小時候
再見小時候 2020-12-01 00:33

I was wondering what methods/preventions other programmers use to stop data being entered twice into a MySQL database when a user refreshes on the same page as a form? Obvio

16条回答
  •  广开言路
    2020-12-01 01:09

    You can use a token to prevent the page from being processed again! Such a procedure is used in a lot web frameworks !

    The pattern you should use is the "Synchronizer Token Pattern"! If you have a serviceoriented application, you can save your status in the Database.

    The data can be send via JavaScript or by a hidden form field.

    You should also have a look at libaries with out of the box support for things like this! Grails is such one!

    See: http://www.grails.org/1.1-Beta3+Release+Notes ...

    
    

    ...

    withForm {
       // good request
    }.invalidToken {
       // bad request
    }
    

    ..

提交回复
热议问题