title: First submit button in HTML is redirecting to different URL
body: <p>I am new to Thymeleaf and trying to Delete the first record but it is redirecting me to <code>http://localhost:8080/findall?_method=delete</code> . Although i am able to delete all the records and they are redirecting me to proper url <code>http://localhost:8080/delete/{id}</code>(except the fist one).</p>
  
  <p>Whenever i am trying to delete the record by hitting the "<a href="http://localhost:8080/delete/" rel="nofollow noreferrer">http://localhost:8080/delete/</a>{id}" from postman, i am able to do it. Thus, this has to do something with .html file.</p>
  
  <p>Here is the code of display.jsp file:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;Registration Table
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form&gt;
    &lt;table border="1"&gt;
      &lt;tr&gt;
        &lt;th&gt;Id&lt;/th&gt;
        &lt;th&gt;Name&lt;/th&gt;
        &lt;th&gt;Password&lt;/th&gt;
        &lt;th&gt;Delete&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr th:each="list : ${list}"&gt;
        &lt;td th:text="${list.id}"&gt;ID&lt;/td&gt;
        &lt;td th:text="${list.userName}"&gt;Name&lt;/td&gt;
        &lt;td th:text="${list.userPassword}"&gt;Password&lt;/td&gt;
        &lt;!--  &lt;td&gt;&lt;a th:href="@{/delete/{id}}"&gt;Edit&lt;/a&gt;&lt;/td&gt; --&gt;
  
        &lt;td&gt;
          &lt;form th:action="@{'/delete/{id}'(id=${list.id})}" th:method="delete"&gt;
            &lt;input type="submit" value="Delete"/&gt;
          &lt;/form&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and here is controller.java</p>
  
  <pre><code>package com.spring.controller;
  
  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
  
  import java.util.List;
  
  import javax.servlet.http.HttpServlet;
  import javax.xml.ws.Response;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.bind.annotation.RestController;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.view.RedirectView;
  
  import com.couchbase.client.deps.io.netty.handler.codec.http.HttpResponse;
  import com.spring.model.Customer;
  import com.spring.repository.CustomerRepo;
  
  @RestController
  public class Controller extends HttpServlet {
  
      @Autowired
      CustomerRepo rp;
  
      @RequestMapping(method = RequestMethod.GET, value = "/findall")
  @ResponseBody
  public ModelAndView findall() {
      List&lt;Customer&gt; list = (List&lt;Customer&gt;) rp.findAll();
      ModelAndView mv = new ModelAndView();
      mv.setViewName("display");
      mv.addObject("list", list);
      for (Customer element : list) {
          System.out.println("Element usernane: " + element.getUserName());
          System.out.println("Element password: " + element.getUserPassword());
      }
      mv.addObject("list", list);
  
      return mv;
  }
  
  
      @RequestMapping(method = RequestMethod.GET, value = "/display")
      @ResponseBody
      public List&lt;Customer&gt; display() {
          return (List&lt;Customer&gt;) rp.findAll();
      }
  
      @RequestMapping("/")
      public ModelAndView home() {
          System.out.println("display home");
          ModelAndView mv = new ModelAndView("home");
          return mv;
      }
  
  
      @RequestMapping(method = RequestMethod.DELETE, value = "/delete/{id}")
      public ModelAndView deleteCourse(@PathVariable Long id) {
          System.out.println("deleting" + id);
          rp.delete(id);
          ModelAndView mv = new ModelAndView("redirect:home");
          return new ModelAndView("redirect:home");
      }
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7YiJB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7YiJB.png" alt="enter image description here"></a></p>
  
  <p>If i click on delete button to delete the first record "Ravi" it will take me to URL "<a href="http://localhost:8080/findall?_method=delete" rel="nofollow noreferrer">http://localhost:8080/findall?_method=delete</a>" and wont delete the record(i want it to take me to url "<a href="http://localhost:8080/delete/1" rel="nofollow noreferrer">http://localhost:8080/delete/1</a>"). But if i click on any other button it is working fine and deleting the record.</p>
  
  <p>I also checked the HTML code on browser. It is not generating same HTML code for each record.
  It should be a very simple fix, Although i didnt find much content on Thymeleaf on stackoverflow.</p>