I seem to remember that is was possible to have several buttons call the post method of the same servlet, then identify the source to find out who called the servlet so the serlet knows which (of several possible services) is desired. I can't find it in memory, notes or javadocs. Anybody know what I'm thinking of?
Prakash Dwivedi
Ranch Hand
Joined: Sep 28, 2002
Posts: 452
posted
0
Create all the submit button with the same name <input type="submit" name="submitbutton" value="action1"> <input type="submit" name="submitbutton" value="action2"> <input type="submit" name="submitbutton" value="action3"> In your servlet request.getParameter("submitbuuton"); This will return the value of the button clicked. I hope this helps
Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
Elouise Kivineva
Ranch Hand
Joined: Feb 07, 2002
Posts: 154
posted
0
Excellent. Thank you!
Stein M. Hugubakken
Greenhorn
Joined: Sep 07, 2003
Posts: 1
posted
0
I'm using this method: protected boolean buttonPressed(String name) { if (req.getParameter(name) != null) return true; else return false; } If the html is something like this: <input type="submit" name="b_ok" value="Ok"> <input type="submit" name="b_cancel" value="Cancel"> you can test for the button like this: if(buttonPressed("b_ok")) handleOk(); else handleCancel(); This method also works when you have several languages for your web-site since you are testing against the name and not the value(label). Stein
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
posted
0
Nitpick: It is never necessary to write code like this: