This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JSP and the fly likes getParameterValues(String) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "getParameterValues(String) " Watch "getParameterValues(String) " New topic


Zeina Afif

Joined: Jul 19, 2001
Posts: 22
I have a form that has parameters with mixed multiple and single values. It is used to create an SQL statement for search.
Is there a way to find out if a Parameter has more than one value in order to use getParameterValues(String) instead of getParameter(String)?
Here's my code:
Vector vParams = new Vector();
Enumeration enum = request.getParameterNames();
while (enum.hasMoreElements()) {
String x = (String)enum.nextElement();
ArrayList aParamValue = new ArrayList();
if((request.getParameter(x) != null) && !(request.getParameter(x).equals(""))){
aParamValue.add(request.getParameterValues (x));
Thanks for any help!
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
getParameterValues() returns an array of Strings. If there is only one value then the array only has one element. So you can just check the size of the array that is returned and then handle it apporpriatley based on the size.
hope that helps

I agree. Here's the link:
subject: getParameterValues(String)
jQuery in Action, 3rd edition