• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

order of request.getParameterValues()

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Joel
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic