This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes order of request.getParameterValues() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "order of request.getParameterValues()" Watch "order of request.getParameterValues()" New topic

order of request.getParameterValues()

Joel Carklin

Joined: Jun 15, 2001
Posts: 28
Hi All,
I have a jsp which iterates through shop offers and presents them in a table on the page.
Therefore I have a number of parameters named offerId, and an equal number of parameters named
quantity. When the form is submitted I want the 'quantity' ordered to match up with the 'offerId', ie quantity[0] will be from the same record as offer[0]
The following code seems to show that they do match up:
String[] offers = request.getParameterValues("offerId");
String[] quantity = request.getParameterValues("quantity");
for(int i=0; i < offers.length; i++)
System.out.println("OfferId: " + offers[i] + " | " + "Quantity: " + quantity[i]);
I just want too make sure though, in the above situation am I guaranteed that the 2 will match up?
I don't want to end up with a situation where accidently the wrong item is ordered or the wrong quantity? Is there a better way to do this?
Thanks for any help
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950

You can't GUARANTEE it - a client/hacker could find it amusing to build the parameters manually, and in the case of input for textfields, I'm not even sure that completely empty fields would be sent anyway. However, if (offers.length != quantity.length) you'll know you have a problem.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: order of request.getParameterValues()
Similar Threads
Errors while compiling
JSP not getting results from Bean
getParameterValues problem
getParameter question
Error while running program