aspose file tools*
The moose likes JSP and the fly likes How to get values from dropdown Select box in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to get values from dropdown Select box in JSP" Watch "How to get values from dropdown Select box in JSP" New topic
Author

How to get values from dropdown Select box in JSP

Maddy Tillie
Greenhorn

Joined: Jan 10, 2002
Posts: 5
Hi Gurus,
I have a JSP Page in which there are drop down select boxes, which are used to search sumthing. Basically i want to get the value selected by the user from drop down select boxes in my JSP. I just wanna show the search results based on the items selected and wanna show what the user has selected from those drop down boxes..
Thanks in advance..
Regards,
Maddy
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Hi,
You can do it by using getParameter method of request object. Suppose the name of the checkbox is "mycheckbox" then use following code:
String value = request.getParameter("mycheckbox");
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

"Maddy",
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
JSP Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Maddy Tillie
Greenhorn

Joined: Jan 10, 2002
Posts: 5
But actually.. the form is submmited to a servlet, whcih is handling as a controller and then that servlet gets the search results and then again redirect to same JSP page.... so how do i get drop down variable in this case...
thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

The name of the parameter will be the name you assigned to the select element. The value of this parameter will be the selected value.
prash po
Greenhorn

Joined: May 12, 2004
Posts: 1
Is there a way to post all the values of a select box or at least all the selected values of a select box to a JSP page.
Like in a multiple selection select box how can I post all the values?
I would like to read all the possible values as well as all the selected values in the JSP.
As far as I know there is no way to do it. But if there is then please let me know.
- P P :roll:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

posted May 12, 2004 02:05 PM Is there a way to post all the values of a select box or at least all the selected values of a select box to a JSP page.
Like in a multiple selection select box how can I post all the values?

The form will automatically post all selected option values. Each selected value will result in a request parameter with the name of the control and the value of the selected option. Be sure to use request.getParameterValues() when retrieving them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get values from dropdown Select box in JSP