Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

get all values from multi <select> in a servlet

843842Feb 4 2010 — edited Feb 7 2010
Hello,

I have a multi <select> element in a HTML form and I need to retrieve the values of ALL selected options of this <select> element in a servlet.

HTML code snippet

<select name="elName" id="elName" multiple="multiple">

Servlet code snippet
response.setContentType("text/html");
PrintWriter out = null;
out = response.getWriter();
String output = "";
String[] str = request.getParameterValues("elName");
for(String s : str) {
output += s + ":";
}
output = output.substring(0, output.length()-1); // cut off last deliminator
out.println(output);
But even when selecting multiple options, the returned text only ever contains the value of the first selected option in the <select>

What am I doing wrong? I'm fairly new to servlets

Edited by: Irish_Fred on Feb 4, 2010 12:43 PM

Edited by: Irish_Fred on Feb 4, 2010 12:44 PM

Edited by: Irish_Fred on Feb 4, 2010 2:14 PM

Edited by: Irish_Fred on Feb 4, 2010 2:26 PM

Edited by: Irish_Fred on Feb 4, 2010 2:26 PM

Edited by: Irish_Fred on Feb 4, 2010 2:32 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2010
Added on Feb 4 2010
3 comments
1,394 views