views:

20

answers:

2

Client code is pretty simple:

<form action="DDServlet" method="post">
       <input type="text" name="customerText">
       <select id="customer">
             <option name="customerOption" value="3"> Tom </option>
             <option name="customerOption" value="2"> Harry </option>
       </select>
       <input type="submit" value="send">
</form>

Here is the code on the Servlet

Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()){
      String paramName = (String)paramNames.nextElement();  //get the next element
      System.out.println(paramName);
}

When I print out, I only see, customerText, but not customerOption. Any idea why guys? What I hope is, if I select Tom in my option, once I submit, on my servlet I should able to do this: String paramValues[] = request.getParameterValues(paramName); and get back value of 3

+2  A: 

You need to put the name attribute on the select. This should fix it up:

<select name="customerOption" id="customer">
    <option value="3"> Tom </option>
    <option value="2"> Harry </option>
</select>
Bialecki
+1, the parameter name will be customerOption, not customer. I usually keep my id and name fields the same, but it doesn't really matter.
darren
thank you very much
Harry Pham
A: 

The code you are showing, you did getParameterNames. Is that just exmaple or is that the mistake?

Fazal
`getParameterNames()` return `Enumeration`, which then u can iterate to all the elements in your form by `hasMoreElement()`. Make sure that your html tag contain `name` attributes.
Harry Pham