By Spring I am assuming you mean Spring MVC.
From the below reference
[To see links please register here]
Here you go -
You create a validator class -
public class UserValidator implements Validator {
public boolean supports(Class candidate) {
return User.class.isAssignableFrom(candidate);
}
public void validate(Object obj, Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "required", "Field is required.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "required", "Field is required.");
}
}
Put in any validation text you want in the above field.
In the JSP you will need the following tag -
<tr>
<td>First Name:</td>
<td><form:input path="firstName" /></td>
<!-- Show errors for firstName field -->
<td><form:errors path="firstName" /></td>
</tr>
This way any validation error for `firstName` will be printed.