@Valid (jsr 303) not working in Spring mvc 3.0

五迷三道 提交于 2019-12-04 18:45:59
user2113762

Adding <mvc:annotation-driven/>in servlet context XML fixed the issue for me.

you are missing form error tag.use like

<table>
<form:form action="login.htm" commandName="logindetails">
    <tr>
        <td>User :</td>
        <td><form:input path="userName" /></td>
        <td><form:errors path="userName" /></td>
    </tr>
    <tr>
        <td>Password :</td>
        <td><form:input path="password" /></td>
        <td><form:errors path="password"  /></td>
    </tr>
    <tr><td><input type="submit" value="Ok"> </tr>
</form:form>

and also you have to maintain property file with error message.

NotEmpty.logindetails.userName = userName is required!
Range.logindetails.password= password value must be between 2 and 3

Example: Click here

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