title: Spring MVC - How do I call the same URL with different mapping annotations
body: <p>I have set up a Controller with two methods. The URL mappings are exactly the same, and the only difference is the mapping annotation method. One is @PostMapping and the other @DeleteMapping written in that order. However, when I try to call the @DeleteMapping method, the @PostMapping method is called.</p>
  
  <p>Note that even though variables in the two URL forms are different, they have the same values. They are just from different HTML pages.</p>
  
  <p>The question is how to call the desired method each time.</p>
  
  <p>@PostMapping method</p>
  
  <pre><code>@Secured({"ROLE_ADMIN", "ROLE_STUDENT"})
  @PostMapping("students/{username}/internships/{id}")
  public String addInternship(Model model, @PathVariable("username") String username, @PathVariable("id") int id) {
  
      /* DOES SOME STUFF
      Student student = userService.getUser(username).getStudent();
      Internship internship = userService.getInternship(id);
  
      StudentInternship studentInternship = new StudentInternship(internship, student, "Sent");
  
      internship.setNumberOfPositions(internship.getNumberOfPositions() - 1);
      userService.updateInternship(internship);
  
      student.setApplicationNumber(student.getApplicationNumber() + 1);
      userService.updateStudent(student);
  
      userService.addStudentInternship(studentInternship);
      */
  
      return "redirect:/internships";
  }
  </code></pre>
  
  <p>@DeleteMapping method</p>
  
  <pre><code>@Secured({"ROLE_ADMIN", "ROLE_STUDENT"})
  @DeleteMapping("students/{username}/internships/{id}")
  public String removeInternship(Model model, @PathVariable("username") String username, @PathVariable("id") int id) {
  
      /* DOES SOME STUFF
      Student student = userService.getUser(username).getStudent();
      Internship internship = userService.getInternship(id);
  
      int studentInternshipID = userService.getStudentInternshipByParams(student, internship).getId();
  
      internship.setNumberOfPositions(internship.getNumberOfPositions() + 1);
      userService.updateInternship(internship);
  
      student.setApplicationNumber(student.getApplicationNumber() - 1);
      userService.updateStudent(student);
  
      userService.removeStudentInternship(studentInternshipID);
      */
  
      return "redirect:/students/" + username + "/internships";
  }
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;form:form action="${pageContext.request.contextPath}/students/${username}/internships/${tempInternship.id}" method="POST"&gt;
      &lt;input type="submit" value="Request" ${disabled}/&gt;
  &lt;/form:form&gt;
  
  &lt;form:form action="${pageContext.request.contextPath}/students/${tempStudentInternship.student.username}/internships/${tempStudentInternship.internship.id}" method="DELETE"&gt;
      &lt;input type="submit" value="Dismiss" /&gt;
  &lt;/form:form&gt;
  </code></pre>