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
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.
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.
Joined: Apr 10, 2002
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