1. 程式人生 > >java-servlet request.getParameterValues()

java-servlet request.getParameterValues()

JSP 使用 request.getParameter(request_fieldname); 只能拿到 array 裡的第1個值。

如果需要拿到整個 array 需要使用 request.getParameterValues()

ex:

If you are using POST method you must use application/x-www-form-urlencoded Content Type or just use Post method in your HTML form. For example:

 <form method="post">
 Habits
: <input type="checkbox" name="habits" value="Reading">Reading <input type="checkbox" name="habits" value="Movies">Movies <input type="checkbox" name="habits" value="Writing">Writing <input type="checkbox" name="habits" value="Singing">Singing <input type
="submit" value="Submit"> </form>

Then in both cases in your servlet:

String[] outerArray=request.getParameterValues('habits');
your array will be filled with separated values:

//["Writing","Singing"]