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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
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: 60045
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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://aspose.com/file-tools
 
subject: Get the button value from request.getParameterValues()
 
Similar Threads
validation particular fields for different actions in a single page
Struts 1.1 refresh with values
Is it possible?
clearing HTML form fields after return from struts validation with errors
Dynamic field collapse issue in Form