繁体   English   中英

JSP表单与列表提交到Spring MVC控制器

[英]Jsp form submit with list to spring MVC controller

我是jsp和spring MVC的新手。 我有一个jsp,它显示学生列表以使用表格中的复选框来参加。 学生jsp包含来自学生表的学生详细信息,复选框来自出勤表,而我的jsp页面是这样的

Jsp代码

            <tr>
                <th width="80">Student No</th>
                <th width="120">Student Name</th>
                <th width="120">Father Name</th>
                <th width="60">Mobile No</th>
                <th width="60">Present</th>
            </tr>
            <c:if test="${!empty studentsList}">
                <c:forEach items="${studentsList}" var="student">
                    <tr>
                        <td>${student.studentId}</td>
                        <td>${student.studentName}</td>
                        <td>${student.fatherName}</td>
                        <td>${student.mobileNo}</td>
                        <td><form:checkbox path="attendance.presentFlag" /></td>
                </c:forEach>
            </c:if> 

    </table>
    <div align="center">
        <tr>
            <td></td>
            <td><input type="submit" value="Present" style="margin-top: 12px;"/></td>
        </tr>
    </div>
    </form:form>

在jsp上方将显示带有复选框的学生列表。 现在我想基于复选框checked标志将jsp中的修改列表提交给spring MVC控制器以存储在数据库中,请问有人可以建议我如何克服将jsp表单提交给spring mvc的问题,我无能为力。 我可以调用控制器的方法来完成列表提交。

创建一个按钮而不是Submit并调用Java脚本函数,然后在应用逻辑后提交表单。

您需要在form标记内添加以下内容:

  • method =“ GET / POST”
  • action =“ $ {request.contextPath} / requestMapping”
  • modelAttribute =“ attendance”

<form:checkbox path="presentFlag" /> ->如果出勤对象具有布尔值“ presentFlag”数组,则将自动绑定值

提交名称和值分别确定请求参数的名称和值。

您的Spring控制器应具有与实际操作相同的请求映射,以及请求参数和模型属性“出勤”。

https://www.mkyong.com/spring-mvc/spring-mvc-checkbox-and-checkboxes-example/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM