aspose file tools
The moose likes JSP and the fly likes Get the button value from request.getParameterValues() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Get the button value from request.getParameterValues()" Watch "Get the button value from request.getParameterValues()" New topic
Author

Get the button value from request.getParameterValues()

H Johan Lekberg
Greenhorn

Joined: Mar 17, 2003
Posts: 4
I have a jsp page that contains a form.
In the form i have several fields and buttons.
I am able to get the values from the fields but now I also want to know witch button that was pressed.
How do I do that?
/Jle
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56549
    
  14

Assuming that the buttons are of type "submit", the easiest way is to just give them all the same name with differing values as in:

You will get a single request parameter named "theButton" which will have the value of the clicked button as its value.
However, since the values are visible (they serve as the caption of the button), you may not be able to have unique values (if all the buttons need to be captioned "OK", for example). In this case you could use unique names for each of the buttons and look through the list of request parameters to see which one got submitted.
If your buttons are not submit buttons, you might have to resort to a small bit of JavaScript.
hth,
bear
[ March 17, 2003: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Marty Hall
Author
Ranch Hand

Joined: Jan 02, 2003
Posts: 111

I am able to get the values from the fields but now I also want to know witch button that was pressed.


Cheers-
- Marty


Java training and consulting<br /><a href="http://www.coreservlets.com/" target="_blank" rel="nofollow">http://www.coreservlets.com/</a>
H Johan Lekberg
Greenhorn

Joined: Mar 17, 2003
Posts: 4
Thank you, it helped!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Get the button value from request.getParameterValues()
 
Similar Threads
clearing HTML form fields after return from struts validation with errors
Is it possible?
Struts 1.1 refresh with values
Dynamic field collapse issue in Form
validation particular fields for different actions in a single page