2010-11-04 153 views
7

根据Spring文档here请求方法 'POST' 不支持

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 method="delete"> 
    <input type="submit" value="Delete"/> 
</form:form> 

的问题是当我点击'删除'我的页面会抛出以下错误:

HTTP Status 405 - Request method 'POST' not supported 

I ch anged的org.springframework.web调试级别来调试,发现以下消息:

DEBUG AnnotationMethodHandlerExceptionResolver - Resolving exception from handler [[email protected]]: 
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported 

我用RestClient用DELETE方法和如预期的方法被调用。我在这里做错了什么?

+0

我想POST作为使用RESTClient实现参数和返回的状态码:405方法不被允许。问题在哪里? – Joopiter 2010-11-04 03:22:31

+0

你可以发布你的控制器吗? – hisdrewness 2010-11-04 05:51:35

+0

@hisdrewness是的,我可以,但我不认为问题出现在控制器的url映射中,因为使用RestClient可以正常工作。 – Joopiter 2010-11-04 07:50:30

回答

5

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

细节可以发现here

+0

我配置了过滤器,并将过滤器映射放置为包含Spring MVC Dispatcher的,但仍然无效。还有其他建议吗? – Joopiter 2010-11-04 07:48:44

+0

更改为 *,结果很好。似乎使用urlrewrite是问题的一部分,因为当我尝试 app/*此过滤器首先在urlrewrite过滤器之前得到验证。感谢maximdim! – Joopiter 2010-11-04 07:59:48

相关问题