在 Hibernate 验证器下在 Spring 中验证表单的问题
我在 Spring 中使用使用 hibenate 验证器进行验证的简单表单时遇到问题 我的表单:
<form:form method="POST" commandName="info">
username:<form:input path="username"/> <form:errors path="username"></form:errors>
password:<form:password path="password"/><form:errors path="password"></form:errors>
<input type="submit" value="add new writer">
</form:form>
我的表单控制器:
@RequestMapping(method=RequestMethod.POST,value={"/createnewuser"})
public String showCreateNewUserFrom( @javax.validation.Valid Information info,Model model,BindingResult br)
{
//System.out.println("hello post");
if(br.hasErrors())
{
return "admin/createuserform";
}
else
return "admin/createuserform";
}
我的问题是当我的表单无效时会抛出异常!我想要 jsp 错误视图
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'information' on field 'username': rejected value [vc]; codes [Size.information.username,Size.username,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [information.username,username]; arguments []; default message [username],10,4]; default message [username must be at least 4 and at most 10 character]
Field error in object 'information' on field 'password': rejected value [fg]; codes [Size.information.password,Size.password,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [information.password,password]; arguments []; default message [password],8,5]; default message [username must be at least 5 and at most 8 character]
我将非常感谢任何帮助
i have a problem with a simple form in spring that use validating with hibenate validator
my form:
<form:form method="POST" commandName="info">
username:<form:input path="username"/> <form:errors path="username"></form:errors>
password:<form:password path="password"/><form:errors path="password"></form:errors>
<input type="submit" value="add new writer">
</form:form>
my controller for form:
@RequestMapping(method=RequestMethod.POST,value={"/createnewuser"})
public String showCreateNewUserFrom( @javax.validation.Valid Information info,Model model,BindingResult br)
{
//System.out.println("hello post");
if(br.hasErrors())
{
return "admin/createuserform";
}
else
return "admin/createuserform";
}
my problem is when my form is invalide that throw exception!!i want jsp view of errors
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'information' on field 'username': rejected value [vc]; codes [Size.information.username,Size.username,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [information.username,username]; arguments []; default message [username],10,4]; default message [username must be at least 4 and at most 10 character]
Field error in object 'information' on field 'password': rejected value [fg]; codes [Size.information.password,Size.password,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [information.password,password]; arguments []; default message [password],8,5]; default message [username must be at least 5 and at most 8 character]
i will be realy greatfull for anyhelp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 文档:
看起来像你的情况..
From documentation:
Looks like your case..