java - 不支持请求方法 'POST'

标签 java spring-mvc url-rewriting

根据 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/

相关文章:

传递查询字符串时,.htaccess 会破坏 CSS 和 Javascript

java - 使用 == 和 != 的奇怪包装类行为

java - 在 Java RegEx 中捕获点和逗号

spring-mvc - 如何在 Spring WebSocket 处理程序中访问 "session"范围的 bean(不是 "websocket"范围)

java - Spring MVC 中不存在必需的字符串参数错误

mod-rewrite - 使用 mod_rewrite 重写基本 URL 并为其添加特定单词

java - 如何在firebase数据库android中存储对象的数组列表

java - 如何在 Android Studio 中添加 Snap to Roads Google Map

java - 如果用户有有效 session ,如何显示主页?

url-rewriting - URL 中的破折号与下划线