请求方法“POST”不受支持 [英] Request method 'POST' not supported

查看:2006
本文介绍了请求方法“POST”不受支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Spring文档此处

According to the Spring Documentation here:


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

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).

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

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

<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

我将 org.springframework.web 的调试级别更改为debug并找到以下消息:

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

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

我用 RestClient ,并按预期调用该方法。我在这里做错了什么?

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

推荐答案

您需要在web.xml中配置HiddenHttpMethodFilter

You need to configure HiddenHttpMethodFilter in your web.xml

详细信息可以在这里找到

这篇关于请求方法“POST”不受支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆