0

完整代码在github: https ://github.com/cuipengfei/MPJSP/tree/master/tmp

在控制器中,有一个处理提交的方法:

@RequestMapping(value = "/home", method = RequestMethod.POST)
    public void handleSubmit(Customer model, BindingResult result) {
        System.out.println(model.getUserName());
        result.rejectValue("userName", "required.userName", "user name invalid");
    }

而在jsp中,有这样一种形式:

<form:form method="POST" action="home" modelAttribute="Customer">

    <table>
        <tr>
            <td>Username :</td>
            <td><form:input path="userName" /></td>
            <td><form:errors path="userName" cssClass="error" /></td>
        </tr>
        <tr>
            <td colspan="3"><input type="submit" /></td>
        </tr>
    </table>
</form:form>

控制器每次都拒绝值,但不显示错误消息。

完整代码可以在这里找到: https ://github.com/cuipengfei/MPJSP/tree/master/tmp

4

1 回答 1

0

尝试在表单标签中设置 commandName 属性

<form:form method="POST" action="home" commandName="Customer">
于 2012-11-20T11:16:10.843 回答