title: Displaying errors set on org.​springframework.​validation.Errors object in jsp
body: <p>I'm using a custom Validator for a form input. I use the <code>org.springframework.validation.ValidationUtils</code> singleton to reject mandatory field entries if they're empty: </p>
  
  <pre><code>ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", null, "Username is mandatory");
  </code></pre>
  
  <p>Printing those error messages works in my jsp:</p>
  
  <pre><code>&lt;form:errors path="username"/&gt;
  </code></pre>
  
  <p>However, I want to do some more 'sophisticated' validation, such as RegEx'ing email input or matching two password entries:</p>
  
  <pre><code>errors.reject("verifypw", "Passwords don't match");
  </code></pre>
  
  <p>When the two entered passwords don't match, I want to add an error to the Errors object.
  This works as intended and I can check on the controller for errors with</p>
  
  <pre><code>public String submitRegisgrationForm(@ModelAttribute("user") PlatformUser user, BindingResult result) {
      userService.validateUserInput(user, result);
      if (!result.hasErrors()) {
          userService.createNewUser(user);
          return "user/success";
      } else {
          return "user/register";
      }
  }
  </code></pre>
  
  <p>Alas, the errors raised through <code>errors.reject()</code> can not be accessed like the ones raised through <code>rejectIfEmptyOrWhitespace()</code>.</p>
  
  <pre><code>&lt;form:errors path="verifypw"/&gt;
  &lt;label for="verifypw"&gt;Verify password: &lt;/label&gt;
  &lt;form:password path="verifypw" id="verifypw"/&gt;
  </code></pre>
  
  <p>This does not print out any error messages to the jsp.</p>