Unable to display error on JSP in Spring MVC validation

Asked on October 04, 2013
Hi All,
I am creating application to validate form in Spring MVC. I am not sure why I am not getting error in JSP. Find my controller.
Controller
@RequestMapping(value="user", method = RequestMethod.GET)
public User user(){
return new User();
}
@RequestMapping(value="createUser", method = RequestMethod.POST)
public ModelAndView createUser(@ModelAttribute("user") @Valid User user,BindingResult result,ModelMap model) {
if(result.hasErrors()) {
return new ModelAndView("redirect:user");
}
model.addAttribute("name",user.getName());
model.addAttribute("age",user.getAge());
model.addAttribute("location",user.getLocation());
return new ModelAndView("redirect:pages/success.jsp");
}
Please help me.

Replied on October 04, 2013
JSP is
<form:form action="createUser" method="post" commandName='user'>
Enter User Name:<form:input path="name"/>
<font color="red"> <form:errors path="name"></form:errors></font><br/>
Enter age :<form:input path="age"/>
<font color="red"><form:errors path="age"></form:errors></font><br/>
Enter location :<form:input path="location"/>
<font color="red"><form:errors path="location" ></form:errors></font><br/>
<input type="submit">
</form:form>

Replied on October 04, 2013
Using redirect will reset all the errors from BindingResult. You need not to use redirect.
Try as
if(result.hasErrors()) {
Try as
if(result.hasErrors()) {
return new ModelAndView("user");
}

Replied on October 04, 2013
Thanks Arvind. It is working.