Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getParameterValues() or getParameter()

 
michael bradly
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a servlet that processes a form. I've managed to get it to work in its simple incarnation, however I've tried to expand upon my success but to no avail. I'm unsure if I can use getParameter() or if I need to use getParameterValues()
My form has two rows with three columns each and is passing values to the following:
item, numItems, priceOfItem
item, numItems, priceOfItem
After connecting to mySQL I'm trying to do this

Any suggestions about what I'm doing wrong is appreciated.
Regards,
Michael
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
You are correct in thinking that you need to call getParameterValues(). This is used when you have more than one parameter with the same name.
 
michael bradly
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So in doing request.getParameterValues(paramName), do I get an array of Objects or just an Object of the value associated with the paramName which then should be cast to String and assigned to an array of String(s)?
String[] getValueOfParam = (String) request.getParameterValues(paramName);
Assuming "item" is the paramName and "apple" is the value, am I right in thinking that getParameterValues(paramName) will only return apple?
Later in my program I'm using a preparedStatement for my insertions and am trying to figure how best to store those items so I can insert them in correct order. I believe I'm starting to grasp the concept, I'd just like to make sure.
Thanks, Michael
Originally posted by Jeanne Boyarsky:
Michael,
You are correct in thinking that you need to call getParameterValues(). This is used when you have more than one parameter with the same name.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
You get an array of Strings, so no casting is necessary. For example:

Yes, if "apple" is the only value associated with it, the first and only element of the array will be "apple."
Note that if there is more than one value associated with the parameter name, you are not guaranteed to get the values in any particular order.
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread would be more appropriate in the Servlet section.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic