title: Showing error message on JSP using BindingResult
body: <p>I am new to Spring.
  I am trying to show error messages on jsp for the wrong user and password by using BindingResult. But the error messages are not showing.</p>
  
  <p>Please suggest me what I is wrong in the below code.</p>
  
  <h2>JSP</h2>
  
  <pre><code>&lt;script type="text/javascript"&gt;      
      function loginUser() {              
          $('#loginForm').submit();    
      }
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;form:form action="login.test" id="loginForm" commandName="loginForm" method="POST"&gt;
      &lt;div class="brand_area"&gt;&lt;/div&gt;
          &lt;div class="content_area"&gt;          
              &lt;table style="top: 360px; position: relative; margin-left: 333px;"&gt;
                  &lt;tr id="uNameID"&gt;
                      &lt;td class="label"&gt;User Name:&lt;/td&gt;
                      &lt;td&gt;&lt;form:input id="userNameID" path="userName" class="textInput" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;form:errors path="userName" class="error"/&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr id="pID"&gt;
                      &lt;td class="label"&gt;Password:&lt;/td&gt;
                      &lt;td&gt;&lt;form:password id="passwordID" path="password" class="textInput" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;form:errors path="password" class="error"/&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;span id="saveButton" class="loginButton"
                          onclick="loginUser()"&gt; &lt;span&gt;Login&lt;/span&gt;
                      &lt;/span&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/div&gt;
      &lt;/form:form&gt;
  </code></pre>
  
  <h2>Controller</h2>
  
  <pre><code>@RequestMapping(value = "login.test", method = RequestMethod.POST)
  public String processForm( LoginForm loginForm, BindingResult result, ModelMap model, HttpSession session) throws SQLException {
  
      String resultedPage;
  
      model.addAttribute("l_nodes", reportService.getAllLiveNodes());
      model.addAttribute("s_nodes", reportService.getAllStaticReportNodes());
  
      User user = userService.getUserByName( loginForm.getUserName() );
  
      if( user != null ){
          session.setAttribute("userID", user.getUserID());
          if( loginForm.getPassword().equals( user.getPassword() ) ){
  
  
              resultedPage = "home/userHome";
  
          }else{
              result.rejectValue( "password", "login.passwordNotValid");
              resultedPage = "redirect:login.test";
          }
      }else{
          result.rejectValue( "userName", "login.userNotValid");
          resultedPage = "redirect:login.test";
      }
  
      return resultedPage;
  }
  </code></pre>
  
  <p>Thanks</p>