从每个循环获取请求参数 [英] get request parameter from a for each loop
问题描述
我有一个带有这样的表的JSP
I have a JSP with a table like this
<table border="1">
<tr>
<th>Step</th>
<th>Date</th>
</tr>
<c:forEach var="myVar" items="${sessionScope.myBean.myList}" varStatus="status">
<tr>
<td><input type="text" name="index" value="${status.count}" disabled></td>
<td><input type="text" name="date" value="${myVar.date}"></td>
</tr>
</c:forEach>
</table>
该表位于表单内,带有提交输入标签.
This table is inside a form, with a submit input tag.
假设myList(bean myBean中的list属性)包含2个元素,我的表正确显示了两行,每行分别带有步骤和日期.
Let's say myList (list attribute in the bean myBean) contains 2 elements, my table correctly displays two lines, with step and date on each line.
比方说,我编辑这两行以在每行上输入一个日期.
Let's say I edit both lines to enter a date on each one of them.
当我单击提交输入时,如何获得两个输入的日期?我怎么知道将它们存储在bean列表中的哪个项目中?
When I click the submit input, how can I get both entered dates ? And how can I know into which item from the bean's list they shall be stored ?
发布表单后,我在debug.request.getParameterNames()上进行了调试,但是它仅包含一个"date"参数.
I looked in debug at request.getParameterNames() after POSTing my form, but it only contains one "date" parameter.
谢谢!
推荐答案
使用HttpServletRequest#getParameterValues()
.这些值与HTML输入元素出现在HTML DOM树中的顺序相同.
Use HttpServletRequest#getParameterValues()
. The values are in the same order as the HTML input elements appear in the HTML DOM tree.
String[] dates = request.getParameterValues("date");
// ...
这篇关于从每个循环获取请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!