This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method to give me the name of the button

 
Elouise Kivineva
Ranch Hand
Posts: 154
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 452
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Elouise Kivineva
Ranch Hand
Posts: 154
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent. Thank you!
 
Stein M. Hugubakken
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitpick: It is never necessary to write code like this:

when you can instead say
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic