13

I know that I can get a parameter like:

HTML

<input type="text" name="field" value="test">

Servlet

String field = request.getParameter("field");

But what if I have multiple input with same name like:

HTML

<input type="text" name="line[]" value="test1">
<input type="text" name="line[]" value="test2">
<input type="text" name="line[]" value="test3">

In PHP I can just use name="line[]" to get an array of all the line inputs. But how to go about this in java?

Servlet pseudo code

String[] lines = request.getParameterArray("line");

for(String line : lines){
    //do shit
}
2

1 Answer 1

17

Close. It's

String[] lines = request.getParameterValues("line");

but the name is line, not line[]

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.