获取“405 - 调用”时不支持请求方法'GET'方法= DELETE [英] Getting "405 - Request method 'GET' not supported when calling" method=DELETE

查看:489
本文介绍了获取“405 - 调用”时不支持请求方法'GET'方法= DELETE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring MVC网络应用程序。在其中有一个按钮的表单,该按钮应该从另一个资源中删除资源:

I have a Spring MVC web app. In it a form with a button that's supposed to delete a resource from another resource:

<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) {

因此理论上服务器应该路由到控制器。但唉它没有,因此是帖子;)

So in theory the server should route to the controller. But alas it does not, hence the post ;)

我得到了

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

显然我没有获取/职位/ id定义了,但我为什么要这样做,我现在想删除..

Obviously I don't have a get for /positions/id defined yet, but why should I, I want to do a delete for now..

(我也试图从我的春季测试中运行它mvc框架在模拟servlet之间没有任何tomcat实现,它给了我一个400 - 错误的请求..

(I'm also trying to run this from my spring-test-mvc framework on a mock servlet without any tomcat implementation in between and it gives me a 400 - bad request.. )

那么我在这里缺少什么?

So what am I missing here?

哦,只是为了削减一些角落:post和get将适用于其他资源,所以其余的设置都没问题。

Oh, just to cut some corners: post and get will work for other resources, so the rest of my setup is fine.

启动服务器甚至告诉我:

The booting server even tells me:

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)

有人像我一样困惑吗?如果不那么,请赐教!

Anyone as confused as I am? If less so, please enlighten me!

推荐答案

表格可以通过 GET POST (也许 PUT ,但我怀疑这是广泛实施的),因为表单提交需要数据传输到服务器的方法。

Forms can be submitted via GET or POST only (maybe also PUT, but I doubt that is widely implemented), as form submission requires a method where data is transmitted to the server.

DELETE 方法没有请求体,因此指定它在表单操作中不受支持。

The DELETE method does not have a request body, so specifying it in a form action is unsupported.

这篇关于获取“405 - 调用”时不支持请求方法'GET'方法= DELETE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆