从jsp到struts检索同名的多个输入

时间:2011-06-11 07:48:00

标签: jsp java-ee struts

我想问一下当我使用ACTIONForm单击SAVE按钮时,如何在循环内的jsp表单中检索同名的值,而不使用request.getParameterValues(“screenName”)的struts中的Action类。

以下是我想从循环内部检索名称“screenName”的示例jsp代码:

           <form action="EditScreeningServlet" method="post">
                <input type = "hidden" name ="applicantNumber" value="${infoObj.applicantNumber}"  >
                <table>
                    <c:forEach var="screen" items="${screenList}">
                        <input type = "hidden" name ="screenId" value="${screen.screenId}"  >
                       <tr>
                           <td>Screen Type: &nbsp</td>       <td>*<input type="text" value="${screen.screenName}" name="screenName" readonly ="true">*</td>
                       </tr>
                       <tr>
                           <td>Date: </td>                   <td><input type="text" value="${screen.screenDate}" name="screenDate" class="date"></td>
                       </tr>
                       <tr> 
                           <td>Result: </td>               
                           <td>
                                <select name = screenResult> 
                                    <option value="Pass" ${screen.screenResult == 'Pass' ? 'selected' : ''}>Pass</option>
                                    <option value="Fail" ${screen.screenResult == 'Fail' ? 'selected' : ''}>Fail</option>
                                    <option value="" ${screen.screenResult == '' ? 'selected' : ''}></option>
                                </select>   
                           </td>
                       </tr>
                        <tr><td>&nbsp</td><td> &nbsp</td></tr>


                    </c:forEach>
                </table>

                <input type="submit" class="saveButton" value="SAVE">
            </form>

1 个答案:

答案 0 :(得分:0)

<form>中你无法获得输入元素数组,但你可以。

<c:forEach var="screen" varStatus="loopStatus" items="${screenList}">
                        <input type = "hidden" name ="screenId" value="${screen.screenId}"  >
                       <tr>
                           <td>Screen Type: </td>
                           <td>*<input type="text" value="${screen.screenName}" name="screenName${loopStatus.count}" readonly ="true">*</td>
                       </tr>
</c:forEach>

或者您可以使用ID与input text element

绑定
<c:forEach var="screen" varStatus="loopStatus" items="${screenList}">
  <tr>
    <td>Screen Type: </td>
    <td>*<input type="text" value="${screen.screenName}" name="screenName${screen.screenId}" readonly ="true">*</td>
  </tr>
</c:forEach>