从表行传递多个具有相同名称的请求参数 [英] Passing multiple request parameters with same name from table rows

查看:94
本文介绍了从表行传递多个具有相同名称的请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有复选框的表,用户可以检查并删除表中的该行.我一切正常,但是如果用户选中两个框,则只会检索表中的第一个框.

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>

这只是我的HTML的一个示例.这是我的servlet的一部分.

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!

推荐答案

当同一个名称上有多个值时,getParameter()实际上仅返回第一个.您需要使用 来获取所有这些值.

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");
// ...

另请参见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆