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

JSP Button Problem

E Wong

Joined: Sep 20, 2004
Posts: 6
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
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Maybe you could use javascript and after clicking the button, disable the button.
Or you could use some constraint like UNIQUE in the database.

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Nov 08, 2001
Posts: 15385
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.

Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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.

Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 642
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.

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
I agree. Here's the link:
subject: JSP Button Problem
It's not a secret anymore!