Passing multiple request parameters with same name from table rows

こ雲淡風輕ζ 提交于 2019-12-07 03:46:27

问题


I have a table with checkboxes that the user can check and delete that row in the table. I have everything working, but if the user checks two boxes, it only retrieves the first one on the table.

<tr>
  <td><input type="checkbox" name="id" value="${user.id}" /></td>
  <td><c:out value="${user.name}" /></td>
  <td><c:out value="${user.email}" /></td>
</tr>

This is just an example of my HTML. Here is part of my servlet.

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

So, again, I can get the first value selected, but I am not able to delete multiple rows on the same table. Is there a function I can use or anything similar? Thanks!


回答1:


The getParameter() indeed returns only the first one when there are multiple values on the same name. You need to use getParameterValues() instead to get all of those values.

String[] ids = request.getParameterValues("id");
// ...

See also:

  • Send an Array with an HTTP Get
  • ServletRequest.getParameterMap() returns Map<String, String[]> and ServletRequest.getParameter() returns String?


来源:https://stackoverflow.com/questions/5953212/passing-multiple-request-parameters-with-same-name-from-table-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!