【发布时间】:2012-07-13 08:53:08
【问题描述】:
我有一个 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
显然我还没有定义 /positions/id 的 get,但我为什么要这样做,我现在想删除..
(我也试图从我的 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)
有人和我一样困惑吗?如果不是这样,请赐教!
【问题讨论】:
标签: java http servlets spring-mvc