3

I want to place the following form:

<input type="hidden" name="MPK[]" value="x" class="MPK"/>
<input type="hidden" name="MPK[]" value="y" class="MPK"/>
<input type="hidden" name="MPK[]" value="z" class="MPK"/>
...

and POST it to servlet or JSP page. How to get values of these inputs in one array in servlet?

request.getParameterValues("MPK");

doesn't work even if i remove [] from names.

2
  • why are you using "input hidden" ? Please post the code of the <form> Commented Oct 23, 2012 at 13:43
  • how do you read the values in you Servlet/JSP? Are you trying with getParameter() or getParameterValues() ? Commented Oct 23, 2012 at 13:56

2 Answers 2

6

You have to get the values from array by parsing it.

String[] mpk;

mpk= request.getParameterValues("mpk");
for(int i = 0; i < mpk.length; i++)
{
System.out.println(mpk[i]);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi i have posted the values but it give me error java.lang.NullPointerException
1

Remove "[]" from you parameter name. e.g.

<input type="hidden" name="MPK" value="x" class="MPK"/>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.