get request parameter from a for each loop

风格不统一 提交于 2019-12-13 03:06:56

问题


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

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