spring-guides / gs-validating-form-input

Validating Form Input :: Learn how to perform form validation with Spring.

Home Page:http://spring.io/guides/gs/validating-form-input/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redirect should be done after success, not after failure

rstoyanchev opened this issue · comments

Currently the controller method is implemented to redirect after validation failure and does not on success. It should be the other way around.

Something like this:

@RequestMapping(value="/", method=RequestMethod.POST)
public String enterAge(@Valid Person person, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return "results";
    }
    return "redirect:/";
}

Guide has been updated based on @rstoyanchev 's tips.