【问题标题】:Why this html button sent get request?为什么这个 html 按钮会发送 get 请求?
【发布时间】:2019-05-13 06:44:09
【问题描述】:

这段代码发送了get请求,为什么?

<form th:action="@{/books/edit/rename}" th:object="${book}" th:method="POST">
        <input type="text" id="id" name="id" th:value="*{id}" value="1"/>
        <input type="text" id="bookName" name="bookName" th:value="*{bookName}" value="nameExample"/>
        <button type="submit">Rename for model</button>
    </form>

【问题讨论】:

  • 有没有可能有一些js处理那个表单?
  • 在浏览器中使用查看源代码并包含浏览器看到的源代码。

标签: java spring post get thymeleaf


【解决方案1】:

尝试去掉方法声明中的th:,如下:

<form th:action="@{/books/edit/rename}" th:object="${book}" method="POST">
…

因为它不读取代码,默认是GET,更多详情请查看https://www.w3.org/TR/html401/interact/forms.html#h-17.3

【讨论】:

  • 没有帮助(请求 URL:localhost:8080/books/edit.html?id=1&bookName=Triller 请求方法:GET
  • @Alexandr 从发布的链接看来,目标似乎也有所不同,因为请求不指向 books/edit/rename 而是 books/edit.html 所以无论你看到的是已经处理的请求,您只是未能删除请求数据,或者实际使用的表单与您发布的表单不同。
猜你喜欢
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 2017-09-10
  • 1970-01-01
  • 2018-06-05
  • 1970-01-01
  • 2019-09-13
相关资源
最近更新 更多