| Author |
how to recognize that which button is pushed
|
gaurav chhabra
Ranch Hand
Joined: Jul 24, 2004
Posts: 109
|
|
sir like i have several buttons in my webpage then how to recognize that which button is pressed if i like to respond differently when different button is pushed. thank you gaurav
|
 |
Hareesh Ram Chanchali
Ranch Hand
Joined: Jan 31, 2005
Posts: 110
|
|
hi, buttons may be different but the button with SUBMIT type within a form will be considered for method (GET or POST). all other u can write as u wish. do not forget that they it should be in <FORM> </FORM> tag
|
Hareesh Ram Chanchali
SCJP 5.0, IBM Certified Solution Designer
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
The one that's not null is the one that was pressed. The other approach, which I like less, is to give all the buttons the same name and read the value of the button. I like this less because the value of a button is the text that the user sees. It's part of the view and shouldn't be used to govern the controller. No matter what value you give to your buttons, inevitably, either a pony tailed web designer or a pointy haired boss will HAVE to change it. If the text is 'Enter' they will need to change it to 'Saved'. It may also need to be internationalized. In any case, when the text is changed, your servlet will break. For this reason I prefer to test the name of the button not the value. Another gotcha, if the user fills out the form and pressed the "Enter" key on the keyboard, the browser will pick the first submit button with both a name and a value and send that as the button that has been pressed.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
 |
|
|
subject: how to recognize that which button is pushed
|
|
|