【问题标题】:Jsp form submit with list to spring MVC controllerJsp表单提交列表到spring MVC控制器
【发布时间】:2017-03-29 07:16:06
【问题描述】:

我是 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 上方将显示带有复选框的学生列表。 现在我想根据复选框选中的标志将jsp中的修改列表提交到spring MVC控制器以存储在数据库中,任何人都可以建议我如何克服jsp表单提交到spring mvc,我无法得到做什么。我可以调用控制器的方法来提交列表。

【问题讨论】:

    标签: java jquery spring servlets


    【解决方案1】:

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

    【讨论】:

    • 能否请您详细建议我在 JavaScript 函数中应该做什么..?
    【解决方案2】:

    在表单标签内你需要一些东西:

    • method="GET/POST"
    • action="${request.contextPath}/requestMapping"
    • modelAttribute="出席"

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

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

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

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

    【讨论】:

    • 感谢您的宝贵建议,我会对此进行锻炼并回复您。
    猜你喜欢
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-05
    • 1970-01-01
    相关资源
    最近更新 更多