Q:

spring validation error message does not dispaly

When I try to use spring validation, the error message doesn't not display. Could you help with this.
My jsp:
<form:form method="POST" modelAttribute="userInfo">     

                <form:label path="redirectURL">Hybris URL</form:label>: 
                <form:input path="redirectURL" placeholder="请填写Hybris管理平台地址"  />
                <form:errors path="redirectURL" class="error" /><br />

                <form:label path="email" >Last Name</form:label>: 
                <form:input path="email" placeholder="请填写邮箱地址" />
                <form:errors path="email" class="error" /><br/>

            <form:input type="hidden" path="taobaoUserId" value= "${taobaouserid}" />
            <input type="submit" class="button" value="提交" style="margin-right: 15px;" />

My validator:
import javax.annotation.Resource;

import org.apache.commons.validator.EmailValidator;
import org.apache.commons.validator.UrlValidator;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.hybris.integration.model.UserInfo;

@Component
public class UserInfoValidator implements Validator {

EmailValidator emailvalidator = EmailValidator.getInstance();

@Override
public boolean supports(Class<?> arg0) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public void validate(Object target, Errors errors) {

    UserInfo userInfo = (UserInfo) target;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "redirectURL",
            "NotEmpty.userInfoForm.redirectURL");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "NotEmpty.userInfoForm.email", "Input info is wrong");

    if (!emailvalidator.isValid(userInfo.getEmail())) {
        errors.rejectValue("email", "Pattern.userInfoForm.email","Input info is wrong");
    }

    if (!userInfo.getRedirectURL().startsWith("http")) {
        errors.rejectValue("redirectURL", "StartWithHttp.userInfoForm.url","Input info is wrong");
    }

    if(validateUrl(userInfo.getRedirectURL())){
        errors.rejectValue("redirectURL", "StartWithHttp.userInfoForm.url","Input info is wrong");
    }
}

private boolean validateUrl(String url) {
    String[] schemes = { "http", "https" };
    UrlValidator urlValidator = new UrlValidator(schemes);
    return urlValidator.isValid(url);
}

}
My controller:
@RequestMapping(value = "redirecttohybris", method = RequestMethod.POST)
public String redirectToInput(Model model,@ModelAttribute("userInfo") 
UserInfo userInfo, BindingResult result )
{

    userInfoValidator.validate(userInfo, result);
    LOGGER.info(userInfo.getTaobaoUserId().toString());
    if (result.hasErrors()) {
        model.addAttribute("userInfo", new UserInfo());
        return "redirectInfo";
    } 

    return "redirect:" + userInfo.getRedirectURL();
}

When I debug, I can see the error related info in "result" in the controller. However, the message is not shown in the front end. I guess there is some problem. Could anyone help with it?

A:

You don't need to reassign the command object, userInfo , when error occurs. You only need to return your view. 
Replacing userInfo with a new UserInfo you are clearing error information.
Try with this:
// ...

if (result.hasErrors()) {
    return "redirectInfo";
} 

// ...

