retrieve multiple inputs of the same name from jsp to struts

给你一囗甜甜゛ 提交于 2019-12-11 13:39:18

问题


I would like to ask how to retrieve the values of the same name in a jsp form inside a loop to the Action class in struts without using the request.getParameterValues("screenName") when I click the SAVE button using the ACtionForm.

Here is the sample jsp code that I would like to retrieve the name "screenName" from the inside the loop:

           <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:


in <form> you can not get as array of input element but you can.

<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>

OR you can use ID to bind with 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>


来源:https://stackoverflow.com/questions/6314787/retrieve-multiple-inputs-of-the-same-name-from-jsp-to-struts

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