File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Avoid submission of form multiple times Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Avoid submission of form multiple times" Watch "Avoid submission of form multiple times" New topic

Avoid submission of form multiple times

Sid Scud
Ranch Hand

Joined: Mar 13, 2001
Posts: 32
If the user clicks the Submit button multiple times in rapid succession, multiple (duplicate)entries are inserted in the DB.
How to avoid this?
Les Dsouza

Joined: Jan 29, 2002
Posts: 27
I guess you could use javascript on the client side for this.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Les, do you have any particular example or documentation that explains how to use javascript in this kind of problem??

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
To prevent website visitors resubmitting the same form data multiple times (by clicking the submit button on a web form, then the back button in the web browser), one can use a no-cache meta tag.
Insert the following HTML tag into the header part of the form template file:
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
Hope this is useful stuff for u

Zakaria Haque
Ranch Hand

Joined: Jan 02, 2002
Posts: 60
Check out hte sychronizer token pattern published in "core j2ee patterns"
Basically what you do is, you give every form a unique ID, and a form can be submitted only once with the same ID. so teh subsequent submitions fail.
The mechnics is:
generate the ID, put it in the form as a hidden field, store the ID in session.
When the form is submitted check if the ID in request matches with the ID in session.
If they match, its a valid (first time) submition, remove the id from session and process the request
If they do not match, the submition is invalid.
If it is not clear and you don't have access to the book, feel free to ask questions.

tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
I agree. Here's the link:
subject: Avoid submission of form multiple times
It's not a secret anymore!