根据 Spring 文档 here :
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 form标签来实现:
<form:form method="delete">
<input type="submit" value="Delete"/>
</form:form>
问题是当我点击“删除”时我的页面抛出以下错误:
HTTP Status 405 - Request method 'POST' not supported
我将org.springframework.web
的调试级别改为debug,发现如下信息:
DEBUG AnnotationMethodHandlerExceptionResolver - Resolving exception from handler [foo.bar.MessageForm@da9246]:
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
我用了RestClient使用 DELETE 方法并按预期调用该方法。我在这里做错了什么?
最佳答案
您需要在您的 web.xml 中配置 HiddenHttpMethodFilter
详情可见here :
关于java - 不支持请求方法 'POST',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4093611/