File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes getParameterValues() or getParameter() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "getParameterValues() or getParameter()" Watch "getParameterValues() or getParameter()" New topic
Author

getParameterValues() or getParameter()

michael bradly
Ranch Hand

Joined: Oct 06, 2000
Posts: 112
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
michael bradly
Ranch Hand

Joined: Oct 06, 2000
Posts: 112
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

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

Joined: Apr 10, 2002
Posts: 170
This thread would be more appropriate in the Servlet section.


Tony Yan<br /> <br />IBM Certified Developer XML and Related Technology<br />Sun Certified Web Component Developer For J2EE Platform<br />Sun Certified Programmer For Java 2 Platform
 
jQuery in Action, 2nd edition
 
subject: getParameterValues() or getParameter()