0

I have a multi select list in a JSP looking like this:

<td><span><b>Delivered by </b>&nbsp;&nbsp;&nbsp;</span></td>
                        <td><select multiple name="deliveredBy">
                                <option value="volvo">one</option>
                                <option value="saab">too</option>
                                <option value="mercedes">three</option>
                                <option value="audi">four</option>
                        </select></td>

By selecting mutliple entries in the list and submitting the form, the entries have the same parameters. The link looks like this:

ReportingArea.jsp?member=fsafd&deliveredBy=volvo&deliveredBy=saab&deliveredBy=mercedes&deliveredBy=audi&calc=two&group1=Butter&Application=

How can I access the individual deliveredBy attributes selected in the list in my Java code ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
matherte
  • 1
  • 3

2 Answers2

0

Just use ServletRequest#getParameterValues().

String[] deliveredBy = request.getParameterValues("deliveredBy");
// ...

Unrelated to the concrete problem, learn servlets before it's too late.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • but I dont want to use the parameters within a servlet. Instead, I want to use it within a normal Java class – matherte Apr 19 '13 at 20:43
  • Just let the servlet pass it to the Java class then? – BalusC Apr 19 '13 at 20:57
  • is it possoble to do that without a servlet? just with a few setters and getters? how? – matherte Apr 19 '13 at 21:21
  • Use a servlet based MVC framework which uses javabeans as model. E.g. JSF, Spring MVC, Struts, etc. This only requires drastic changes to the JSP file in order to properly act as a view to the model. E.g. in JSF, you need to replace ` – BalusC Apr 19 '13 at 21:23
0
String[] deliveredBy = request.getParameterValues("deliveredBy")

for(int i=0;i<deliveredBy.length;i++)
 System.out.println(deliveredBy[i]);
samba
  • 2,263
  • 2
  • 13
  • 13