I use jsp to write a application, and i encounter such a problem, that the browser will always cache the URL i execute, so when user refresh the page, the action will be execute again. for example: ">transfer; if i clicked the link, and after that , i refresh the page, this action will be execute again. I also know, that i need to use to avoid this problem, but it is really not convenient.
Any one have a better solution ? Any suggestions will be appreciated. Thanks in advance.
You typically have a hidden form variable, that has been generated on the first request and saved into the session. Generate it as a random number.
Then, on submission, you check this hidden field, and check the session variable, and if the match, process it, and remove the session variable.
Thus, pressing back will result in the same variable in the form, but removed in the session, so you can trivially detect the case.
This solution works with Internet Explorer.
You can use something known as a token. In your form submission include the token number as a hidden form element. While generating your page, add this random token to your SESSIONS (in an array). Now, on form submission, check if the random token exists in the SESSION array, if yes, then remove it and continue. If no, then throw an error.