When using Select in a form, how do i send the multiple selections to a servlet?

Hi, I'm trying to figure out how to write a servlet that has a Select in which users can select multiple entries, and a
submit button that sends the values of the selected attributes to a servlet.  Here's a simple example i tried to make,
but it doesn't work (the servlet recieves only the first of the selected items).  Please help

;test.servlet
(servlet (age)
    (case age ((#null)
        {<html><head><title>Test Form</title></head>  
         <body>  
           <form method="get" action="test.servlet">  
             Select sereval of these numbers:
             <select name=age size=5 multiple>  
               <option value=10> 10 </option>
               <option value=20> 20 </option>
               <option value=30> 30 </option>
               <option value=40> 40 </option>
               <option value=50> 50 </option>
             <input type="submit">  
             </select>
           </form>  
         </body></html>})
     (else
       {<html><head><title>Test Form</title></head>  
        <body>  
           You selected
           [age]
        </body></html>})))

pavelmedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bubbledragonCommented:
use String array?

String[] arrValues[] = request.getParameterValues("age");
0
jessegivyDeveloperCommented:
Hi bubbledragon,

The second set of brackets aren't required right?  Happens to the best of us, should look like this:

String[] arrValues = request.getParameterValues("age");
0
pavelmedAuthor Commented:
I'm not really sure what you meab by :
String[] arrValues = request.getParameterValues("age");
That looks like Java.
I am using JScheme for my servlet.  (http://www-swiss.ai.mit.edu/~jaffer/r4rs_toc.html)
Could you please show how and where to insert that in my code (because just putting it
in before [age] on the second to last line doesn't work).

Thanks a lot


-------------
Also, in the above code i accidentally put the  <input type="submit">   inside the select.  
So here's the corrected code:

;test.servlet
(servlet (age)
    (case age ((#null)
        {<html><head><title>Test Form</title></head>  
         <body>  
           <form method="get" action="test.servlet">  
             Select sereval of these numbers:
             <select name=age size=5 multiple>  
               <option value=10> 10 </option>
               <option value=20> 20 </option>
               <option value=30> 30 </option>
               <option value=40> 40 </option>
               <option value=50> 50 </option>
             <input type="submit">  
             </select>
           </form>  
         </body></html>})
     (else
       {<html><head><title>Test Form</title></head>  
        <body>  
           You selected
           [age]
        </body></html>})))
0
jessegivyDeveloperCommented:
You just insert it in the page that's slotted to recieve the data wherever you need to access the data.  Usually there's some validation like:

if(request.getParameter("submitButton")!=null)
{
   String[] arrValues = request.getParameterValues("age");
   sql=conn.prepareStatement("UPDATE users SET age=? WHERE user_id=?")
   for(int i=0;i<srrValues.length;i++)
   {
       sql.setString(1,arrValues[i]);
       sql.setString(2,userID);
       sql.executeUpdate();
   }
}

...and keep in mind that the above code is merely a SIMPLE example, not intended for you to base your development on, just to get the idea across, I'm sure you're updating more than just age.  In fact, if you'd like a clearer code sample you'll need to post some of your logic i.e. what you're trying to do and what you're unclear about?

~Jesse
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jessegivyDeveloperCommented:
...sorry, and as to where, it's at the top of the page, or really, it doesn't exactly matter where it is.  I'm NOT familiar with JScheme, I'll check it out.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.