我有一个Spring MVC web应用。其中一个表单带有一个按钮,用于从另一个资源中删除一个资源:
<td>
<form action="/product-bases/${productBase.id}/positions/${position.id}" method="DELETE">
<input type="submit" value="delete" />
</form>
</td>我的控制器:
@Controller
@RequestMapping(value = "/product-bases/{id}/positions")
public class ProductBasePositionController {
@RequestMapping(value = "/{positionId}", method = RequestMethod.DELETE)
public ModelAndView delete(@PathVariable Integer productBaseId, @PathVariable Integer positionId) {所以从理论上讲,服务器应该路由到控制器。但可惜它不是,所以才有了这篇文章。)
我得到了
HTTP Status 405 - Request method 'GET' not supported
type Status report
message Request method 'GET' not supported
description The specified HTTP method is not allowed for the requested resource (Request method 'GET' not supported).
Apache Tomcat/7.0.19显然,我还没有定义get for /positions/id,但是为什么我要,我现在想做一个delete ..
(我还试图从我的spring-test-mvc框架在一个模拟servlet上运行它,中间没有任何tomcat实现,它给了我一个400个错误的请求。)
那么我在这里错过了什么呢?
哦,只是走捷径: post和get将适用于其他资源,所以我的其余设置都很好。
引导服务器甚至告诉我:
RequestMappingHandlerMapping [INFO] Mapped "{[/product-bases/{id}/positions/{positionId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView our.view.controller.ProductBasePositionController.delete(java.lang.Integer,java.lang.Integer)有没有人和我一样困惑?如果不是这样的话,请多多指教!
发布于 2012-07-13 21:45:42
表单只能通过GET或POST (也可能是PUT,但我怀疑它是否得到广泛实现)提交,因为表单提交需要一种将数据传输到服务器的方法。
DELETE方法没有请求正文,因此不支持在表单操作中指定它。
发布于 2012-07-14 02:10:47
你的web.xml里有HiddenHttpMethodFilter过滤器吗?
<filter>
<filter-name>hiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>http://static.springsource.org/spring/docs/current/spring-framework-reference/html/view.html#rest-method-conversion
发布于 2012-07-13 21:46:11
错误消息指示浏览器实际上发送的是GET请求,而不是DELETE请求。
您需要做的是:
https://stackoverflow.com/questions/11471604
复制相似问题