title: Using Posting a form with Spring Boot and Thymleaf incorrectly uses GET method instead of POST
body: <p>I'm learning Spring Boot and am attempting to implement authentication. I have a signup page that uses a POST method to send new user data to be stored in an in-memory database. The weird thing that is happening is that when I submit the form the GET method is the only one that gets called. Here is my HTML file:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;title&gt;Signup&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class=&quot;container justify-content-center w-25 p-3&quot; style=&quot;background-color: #eeeeee; margin-top: 5em;&quot;&gt;
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;label&gt;&lt;a th:href=&quot;@{/login}&quot;&gt;Back to Login&lt;/a&gt;&lt;/label&gt;
          &lt;/div&gt;
  
          &lt;h1 class=&quot;display-5&quot;&gt;Sign Up&lt;/h1&gt;
          &lt;form action=&quot;#&quot; th:action=&quot;@{/signup}&quot; methond=&quot;POST&quot;&gt;
              &lt;div id=&quot;success-msg&quot; th:if=&quot;${signupSuccess}&quot;&gt;
                  You successfully signed up! Please continue to the &lt;a id=&quot;login-ling&quot; th:href=&quot;@{/login}&quot;&gt;login&lt;/a&gt; page.
              &lt;/div&gt;
              &lt;div if=&quot;error-msg&quot; th:if=&quot;${signupError}&quot;&gt;
                  &lt;span th:text=&quot;${signupError}&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-row&quot;&gt;
                  &lt;div class=&quot;form-group col-md-6&quot;&gt;
                      &lt;label for=&quot;inputFirstName&quot;&gt;First Name&lt;/label&gt;
                      &lt;input type=&quot;input&quot; name=&quot;firstName&quot; class=&quot;form-control&quot; id=&quot;inputFirstName&quot; placeholder=&quot;Enter First Name&quot; maxlength=&quot;20&quot; required&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;form-group col-md-6&quot;&gt;
                      &lt;label for=&quot;inputLastName&quot;&gt;Last Name&lt;/label&gt;
                      &lt;input type=&quot;input&quot; name=&quot;lastName&quot; class=&quot;form-control&quot; id=&quot;inputLastName&quot; placeholder=&quot;Enter Last Name&quot; maxlength=&quot;20&quot; required&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-row&quot;&gt;
                  &lt;div class=&quot;form-group col-md-6&quot;&gt;
                      &lt;label for=&quot;inputUsername&quot;&gt;Username&lt;/label&gt;
                      &lt;input type=&quot;input&quot; name=&quot;username&quot; class=&quot;form-control&quot; id=&quot;inputUsername&quot; placeholder=&quot;Enter Username&quot; maxlength=&quot;20&quot; required&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;form-group col-md-6&quot;&gt;
                      &lt;label for=&quot;inputPassword&quot;&gt;Password&lt;/label&gt;
                      &lt;input type=&quot;password&quot; name=&quot;password&quot; class=&quot;form-control&quot; id=&quot;inputPassword&quot; placeholder=&quot;Enter Password&quot; maxlength=&quot;20&quot; required&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;button id=&quot;submit-button&quot; type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Sign Up&lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>As you can see I have the <code>method=&quot;POST&quot;</code> attribute on the form.</p>
  <p>Here is my signup controller:</p>
  <pre><code>import com.udacity.mvc.Basics.models.User;
  import com.udacity.mvc.Basics.services.UserService;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  @Controller()
  @RequestMapping(&quot;/signup&quot;)
  public class SignupController {
  
      private final UserService userService;
  
      public SignupController(UserService userService) {
          this.userService = userService;
      }
  
      @GetMapping()
      public String signupView() {
          System.out.println(&quot;Get&quot;);
          return &quot;signup&quot;;
      }
  
      @PostMapping()
      public String signupUser(@ModelAttribute User user, Model model) {
          String signupError = null;
          System.out.println(&quot;Post&quot;);
          if (!userService.usUsernameAvailable(user.getUsername())) {
              signupError = &quot;The username already exist.&quot;;
          }
  
          if (signupError == null) {
              int rowsAdded = userService.createUser(user);
              if(rowsAdded &lt; 0) {
                  signupError = &quot;There was an error signing you up. Please try again&quot;;
              }
          }
  
          if (signupError == null) {
              model.addAttribute(&quot;signupSuccess&quot;, true);
          } else {
              model.addAttribute(&quot;signupError&quot;, signupError);
          }
  
          return&quot;signup&quot;;
      }
  }
  </code></pre>
  <p>I've placed <code>System.out.println(&quot;GET&quot;)</code> in the @GetMapping() method and can see on my server that that method is called even when I hit the submit button on the signup form. Does anybody know why this is happening?</p>