title: Login form: @RequestMapping cannot handle the POST request
body: <p>I'm new to Spring.</p>
  
  <p>I'm trying to validate a form using annotations that I put in <code>UserForm</code> Class.</p>
  
  <p>Somehow post method does not run at all. </p>
  
  <p>I can see the POST request in the browser but the controller POST method won't run. </p>
  
  <p>Here is my <code>LoginController</code> Class:</p>
  
  <pre><code>@Controller
  public class LoginController {
  
      @RequestMapping(value = "/login", method = RequestMethod.GET)
      public String login(Map&lt;String, Object&gt; model) {
          UserForm loginUser = new UserForm();
          model.put("userForm", loginUser);
  
          return "Login";
      }
  
      @RequestMapping(value = "/login", method = RequestMethod.POST)
      public String doLogin(
              @Valid @ModelAttribute("userForm") UserForm userForm,
              BindingResult result, 
              Map&lt;String, Object&gt; model) {
  
          if (result.hasErrors()) {
              return "Login";
          }
  
          return "Home";
      }
  }
  </code></pre>
  
  <p>Any help pointers appreciated .</p>
  
  <p><strong>Edit:</strong>
  Here is my form:</p>
  
  <pre><code>&lt;form:form action="/bookmarks/login" method="POST" commandName="userForm"&gt;
      &lt;label for="idInput"&gt;Username:&lt;/label&gt;
      &lt;form:input type="text" path="username" placeholder="Username" /&gt;
      &lt;div&gt;&lt;form:errors path="username" cssClass="error"/&gt;&lt;/div&gt;
      &lt;br&gt;
      &lt;label for="idInput"&gt;Passwors:&lt;/label&gt;
      &lt;form:input type="password" path="password" placeholder="Password" /&gt;
      &lt;div&gt;&lt;form:errors path="password" cssClass="error"/&gt;&lt;/div&gt;
      &lt;br&gt;
      &lt;button type="submit" value="login"&gt;Submit&lt;/button&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>This is my <code>security.xml</code> with added <code>login-processing-url="/j_spring_security_check"</code>. This actually solved my problem, but I can not fully explain why:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      ...
      &lt;security:http auto-config="true" use-expressions="true"&gt;
          &lt;security:form-login 
              login-page="/login" 
              default-target-url="/" 
              login-processing-url="/j_spring_security_check"/&gt;
              &lt;!-- authentication-failure-url="/login.html?error=true" /&gt; --&gt; &lt;!-- /login.html?error=true --&gt;
          &lt;!-- default-target-url="/homepage.html" --&gt;
          &lt;security:csrf disabled="true"/&gt;
          &lt;security:intercept-url 
              pattern="/login" access="permitAll"/&gt;
          &lt;!-- &lt;security:intercept-url pattern="/studentRegister" access="permitAll"/&gt; --&gt;
          &lt;security:intercept-url 
              pattern="/**" access="hasRole('USER')"/&gt;
          &lt;security:logout 
              logout-success-url="/login?logout=true"
              invalidate-session="true"
              delete-cookies="JSESSIONID"/&gt;
          &lt;security:session-management
              invalid-session-url="/login"&gt;&lt;/security:session-management&gt;
      &lt;/security:http&gt;
      &lt;bean id="userDetailsService" class="bg.jwd.bookmarks.security.UserDetailsServiceImpl" /&gt;
      &lt;security:authentication-manager&gt;
          &lt;security:authentication-provider
              user-service-ref="userDetailsService"&gt;
              &lt;security:password-encoder hash="md5" /&gt;
          &lt;/security:authentication-provider&gt;
      &lt;/security:authentication-manager&gt;
      &lt;security:global-method-security secured-annotations="enabled" /&gt;
  &lt;/beans&gt;
  </code></pre>