Java 不支持请求方法“POST”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4093611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:32:32  来源:igfitidea点击:

Request method 'POST' not supported

javaspring-mvcurl-rewriting

提问by Joopiter

According to the Spring Documentation here:

根据此处的 Spring 文档:

While HTTP defines these four methods, HTML only supports two: GET and POST. Fortunately, there are two possible workarounds: you can either use JavaScript to do your PUT or DELETE, or simply do a POST with the 'real' method as an additional parameter (modeled as a hidden input field in an HTML form).

虽然 HTTP 定义了这四种方法,但 HTML 只支持两种:GET 和 POST。幸运的是,有两种可能的解决方法:您可以使用 JavaScript 来执行 PUT 或 DELETE,或者简单地使用 'real' 方法作为附加参数执行 POST(建模为 HTML 表单中的隐藏输入字段)。

They have done the latter, and can be achieved with the following spring MVC form tag:

他们已经完成了后者,并且可以使用以下 spring MVC 表单标记来实现:

<form:form method="delete">
   <input type="submit" value="Delete"/>
</form:form>

The problem is when i click 'Delete' my page throws the following error:

问题是当我单击“删除”时,我的页面会引发以下错误:

HTTP Status 405 - Request method 'POST' not supported

I changed the debug level of org.springframework.webto debug and found the following message:

我将调试级别更改org.springframework.web为调试并发现以下消息:

DEBUG AnnotationMethodHandlerExceptionResolver - Resolving exception from handler [foo.bar.MessageForm@da9246]:
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported

I used RestClientwith DELETE method and the method is called as expected. What am I doing wrong here?

我将RestClient与 DELETE 方法一起使用,并且该方法按预期调用。我在这里做错了什么?

采纳答案by maximdim

You need to configure HiddenHttpMethodFilter in your web.xml

你需要在你的 web.xml 中配置 HiddenHttpMethodFilter

Details can be found here:

详细信息可以在这里找到: