Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST array of values to java servlet

Tags:

java

arrays

post

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.

like image 621
ANTARA Avatar asked Jun 20 '26 11:06

ANTARA


1 Answers

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]);
}
like image 59
vikiiii Avatar answered Jun 22 '26 01:06

vikiiii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!