• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Method to give me the name of the button

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent. Thank you!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nitpick: It is never necessary to write code like this:

when you can instead say
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic