In my jsp, I have two buttons that submit the form. The action of the form redirects to a servlet. I want, in my servlet, to know which button has been pressed. Is there a way to differentiate between the two buttons ?
Asked
Active
Viewed 904 times
1
-
1Duplicate of http://stackoverflow.com/questions/11830351/multiple-submit-buttons-in-the-same-form-calling-different-servlets – Algorithmist Apr 17 '13 at 16:59
-
This post may help also. http://stackoverflow.com/questions/15975810/differentiate-between-two-submit-buttons-in-a-form-using-javascript – Susie Apr 17 '13 at 18:04
1 Answers
1
The name of the submit button that is clicked is included as part of the request data.
So:
<input type="submit" name="submit1"/>
<input type="submit" name="submit2"/>
If you were to click on one of these, then you get, effectively, submit1=
or submit2=
as a query parameter in the request. You'll only get the one that is clicked, not the other. You can test the existence of the value in the payload, even though it will have no actual value associated with it.

Will Hartung
- 115,893
- 19
- 128
- 203