Hello,
I have an HTML form which has an drop down box. I want to display the
selected option from this from a Servlet. I am having problems with
this and have a feeling I am not extracting data from the drop-down
box properly. I would be really thankful if somebody can point out
what the error is. The Servlet sends the response but only 0 is
displayed while the user's choice might have been 1 or 2 or 3 or 4.
The drop down box code in html is as follows:
<td>Socks</td>
<td>4</td>
<td><select name="socks" size="1">
<option selected="selected" value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select></td>
</tr>
<tr>
<td>Shirt</td>
<td>16</td>
<td><select name="shirt" size="1">
<option selected="selected" value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select></td>
</tr>
The Servlet code for extraction is here:
// extract data from the drop-down buttons here
int sockQuantity =
Integer.parseInt(request.getParameter("socks"));
int shirtQuantity =
Integer.parseInt(request.getParameter("shirt"));
int trouserQuantity =
Integer.parseInt(request.getParameter("trouser"));
int jumperQuantity =
Integer.parseInt(request.getParameter("jumper"));
int shoeQuantity =
Integer.parseInt(request.getParameter("shoes"));
Thanks in advance.
ros060
Lew - 10 Mar 2007 02:05 GMT
> <td>Socks</td>
> <td>4</td>
[quoted text clipped - 17 lines]
> </select></td>
> </tr>
Dude, lose the TAB characters. Use spaces for Usenet posts.
-- Lew
mart - 12 Mar 2007 12:03 GMT
Hello do you not need to use request.getParameterValues() which would
return an array of values, strings.
Something like this, where getParameterValues() returns an array of
Strings.
String[] myShirts = request.getParameterValues("shirts");
then you could loop over the array and parseInt off everything.
for(int i=0;i<myShirts.length;i++){
int shirtQuantity = Integer.parseIn(myShirts[i];
}
I am still a bit of a newbie at this stuff myself and I did not test
this but something along these
lines should do it.
hope it helps
cheers
Martin
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html#
getParameterValues(java.lang.String)
> Hello,
>
[quoted text clipped - 29 lines]
>
> The Servlet code for extraction is here:
> // extract data from the drop-down buttons here
> int sockQuantity =
[quoted text clipped - 10 lines]
> Thanks in advance.
> ros060