Unable to retrieve parametername of the selection box through a servlet

Hi All,
 I have a JSP which when executed calls a servlet.
Tis Jsp has couple of text fields and checkboxes and two selection boxes.
WHen I make a call to get parameternames for all the components in the JSP. I aget everything except the names of the selection boxes.
Anyhelp soon will be appreciated.
Thanks
Azhar
aarschieAsked:
Who is Participating?
 
bobbit31Commented:
just make a default option like:

<option value=-1 selected>Choose whatever</option>

then just make sure the user selects an option
0
 
bobbit31Commented:
that's b/c you have to select an item in the selection box... otherwise no value from it will be passed (hence no parameter).
0
 
vk33Commented:
Make sure you've defined the names of selection boxes in the form. And check out the spelling in both the form and the servlet.

Regards!
0
 
vk33Commented:
JSP code:

<form action="Demo" method="POST">
<select name="sel">
      <option value="123">bla-bla-bla</option>
</select>
<input type="submit">
</form>

Servlet code:
PrintWriter out = null;
try {
      out = response.getWriter();
      String param = request.getParameter("sel");
      out.println (param);
} catch (Exception e) {
      if (out != null)
            out.println (e.toString());
}

It works fine, I've checked...

Good luck!
0
 
vk33Commented:
Khm, sorry, I misunderstood the question... Include the following to the servlet code above:

Enumeration enumParams = request.getParameterNames();
while (enumParams.hasMoreElements())
   out.println((String)enumParams.nextElement());

But still it works fine, you'll get "sel" param name printed out.
Tested on Tomcat-4.1.18

Regards!
0
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.

All Courses

From novice to tech pro — start learning today.