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[]

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.