aspose file tools*
The moose likes Servlets and the fly likes Method to give me the name of the button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Method to give me the name of the button" Watch "Method to give me the name of the button" New topic
Author

Method to give me the name of the button

Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
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
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
Excellent. Thank you!
Stein M. Hugubakken
Greenhorn

Joined: Sep 07, 2003
Posts: 1
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
Nitpick: It is never necessary to write code like this:

when you can instead say


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method to give me the name of the button
 
Similar Threads
Finding references across projects in Eclipse
Johannes' assigment log edititing????
Can I use RequestDispatcher to open a new browser window
Logging and reflection/introspection
Form being Submitted several times.