Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Button Problem

 
E Wong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i'm experiencing a problem with JSP Buttons.
The scenario is as follows.

My "Submit" button is linked directly to the DB and whenever that button is clicked, an entry is recorded. Each entry is meant to be unique. However, during testing, i realized that if you double click on the button, 2 similar entries will be added into the database. The only difference would be the time of entry, which would vary by about 1 second or so.

My question is, is there a way to control this problem?

The codes are as follows

INPUT TYPE=submit VALUE='Yes' style="width:80" name=cmdYes
INPUT TYPE=button VALUE='No' style="width:80" name=cmdNo
Hopefully someone can help me in this situation

Best regards
weugene
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could use javascript and after clicking the button, disable the button.
Or you could use some constraint like UNIQUE in the database.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first of all avoid duplicate entries in your table, use primary key.

about submit button. you can try to a simple "button" instead of "submit". and then onClick event submit your form through javascript. not sure it would help you or not. just try it out.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript should not be your answer, you should deal with it on the server side!

Check to see if the record exists before adding the information to the database.

Eric
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, if dont want to request the server for this kind of thing. I really dont want the double click to work then what I can do?

And ofcourse never rely on client side only. we should do our every type of validations on server-side. And I think if we have our table well defined with constraints like, PK, UK; as I said. then all we have to handle is the thrown exception.

Thanx.
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, i dont want to request the server for this kind of thing


And ofcourse never rely on client side only


Is there 3rd option avilable on Earth ??

If you dont want to alow double click then use javascript.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic