问题
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.
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.
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 ?
I looked in debug at request.getParameterNames() after POSTing my form, but it only contains one "date" parameter.
Thanks !
回答1:
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");
// ...
来源:https://stackoverflow.com/questions/14695816/get-request-parameter-from-a-for-each-loop