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

发布于 2024-11-15 02:44:54 字数 2093 浏览 0 评论 0原文

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

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

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

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:  </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> </td><td>  </td></tr>


                    </c:forEach>
                </table>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

地狱即天堂 2024-11-22 02:44:54

中,您无法获取输入元素的数组,但可以。

<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 与输入文本元素绑定

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文