Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Form Servlet

Thread view: 
roohbir - 09 Mar 2007 22:57 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.