form:errors not displaying errors on JSP in Spring
I want to cr开发者_JAVA技巧eate simple form which will display errors if input is not proper means if validation fails. I am using spring 3.0 annotations.
I did following things
1 : Created JSP 2 : Created Controller 3 : Created DTO 4 : Created org.springframework.validation.Validator (write an implementation the necessary methods)
int error = bindingResult.getErrorCount() returning the error count and even my page is not being submitted which is expected but my JSP is not showing error messages
I have write on JSP.
Please guide me how to do this.
If i miss on something please let me know i will paste it.
Have a look at this answer for the structure of the controller. The important think is to have a paramter BindingResult
and if this binding result contains an error you must return the same view (not redirect) again.
In the jsp code you can use the spring errors tag.
@see Spring Reference chapter 16.2.4.14 The errors tag -- there is an example
I have solved this i have just mentioned dto object name in @ModelAttribute
public void myMethod(@Valid @ModelAttribute**("myDto")** MyDTO myDTO,
BindingResult bindingResult, ActionResponse response,
SessionStatus sessionStatus)
精彩评论