从表行传递多个具有相同名称的请求参数 [英] Passing multiple request parameters with same name from table rows
问题描述
我有一个带有复选框的表,用户可以检查并删除表中的该行.我一切正常,但是如果用户选中两个框,则只会检索表中的第一个框.
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");
// ...
另请参见:
- 使用HTTP Get发送阵列
- ServletRequest.getParameterMap()返回Map< String,String []> ;和ServletRequest.getParameter()返回String吗?
- Send an Array with an HTTP Get
- ServletRequest.getParameterMap() returns Map<String, String[]> and ServletRequest.getParameter() returns String?
See also:
这篇关于从表行传递多个具有相同名称的请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!