title: Spring MVC Form - Request method 'GET' not supported
body: <p>I am trying to learn Spring MVC but I don't know how to solve this problem.</p>
  
  <p>Why do I get "Request method 'GET' not supported" when I got to URL "<a href="http://localhost:8080/SpringTest3/addStudent.html" rel="nofollow">http://localhost:8080/SpringTest3/addStudent.html</a>"?</p>
  
  <p>StudentController.java:</p>
  
  <pre><code>package com.springtest3;
  
  import javax.validation.Valid;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.SessionAttributes;
  import org.springframework.web.servlet.ModelAndView;
  
  @Controller
  @SessionAttributes
  public class StudentController {
  
     @RequestMapping(value = "/students", method = RequestMethod.GET)
     public ModelAndView showStudent() {
        return new ModelAndView("student", "command", new Student());
     }
  
     @RequestMapping(value = "/addStudent", method = RequestMethod.POST)
     public String addStudent(@ModelAttribute("student") Student student, BindingResult result/*, final ModelMap model*/) {
         if (result.hasErrors()) {
             System.out.println("ERROR ERROR ERROR");
         }
  
         /*model.addAttribute("name", student.getName());
         model.addAttribute("age", student.getAge());
         model.addAttribute("id", student.getId());*/
  
         System.out.println("Name: " + student.getName());
  
        return "redirect:students.html";
     }
  }
  </code></pre>
  
  <p>addStudent.jsp:</p>
  
  <pre><code>&lt;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Spring MVC Form Handling&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h2&gt;Student Information&lt;/h2&gt;
  &lt;form:form method="post" action="addStudent.html"&gt;
     &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="name"&gt;Name&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="name" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="age"&gt;Age&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="age" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="id"&gt;id&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="id" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td colspan="2"&gt;
              &lt;input type="submit" value="Submit"/&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;  
  &lt;/form:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><br>
  <strong>Solution:</strong><br>
  As suggested below I added this method in StudentController.java: </p>
  
  <pre><code>   @RequestMapping(value = "/addStudent", method = RequestMethod.GET)
     public void test(Model model) {
         model.addAttribute("student", new Student());       
     }
  </code></pre>
  
  <p>But I also need to change the following line in addStudent.jsp: </p>
  
  <pre><code>&lt;form:form method="post" action="addStudent.html"&gt;
  </code></pre>
  
  <p>to</p>
  
  <pre><code>&lt;form:form method="post" modelAttribute="student" action="addStudent.html"&gt;
  </code></pre>