Servlet HTTP method GET is not supported HTTP 405

写好一个Servlet后访问时抛出"HTTP method GET is not supported by this URL"的错误,先是自己找了一下原因,后又在网络查找相关的原因后找到解决方案。

问题的原因是用Eclipse生成Servlet时,会在doGet和doPost自动添加默认调用父类的构造方法,如下红色标识代码:

/**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        super.doGet(request, response);
    }
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        super.doPost(request, response);
    }

这个时候就会有个问题,如果直接调用父类的方法,就相当于父类HttpServlet的doGet或doPost方法覆盖了你重写的方法,而父类 HttpServlet的doGet或doPost方法的默认实现是返回状态代码为405的HTTP错误,表示对于指定资源的请求方法不被允许。删除以上 代码当中调用父类的方法后问题迎刃而解。

时间: 2024-08-24 18:39:51

Servlet HTTP method GET is not supported HTTP 405的相关文章

Eclipse在创建dynamic web时出现HTTP method GET is not supported by this URL错误

显然错误的原因是没有重写servlet的doGet方法,只是覆盖了doPost的方法. 解决的方法很简单: 1 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{ 2 this.doPost(req, resp); 3 } Eclipse在创建dynamic web时出现HTTP method GET is not supported b

HTTP method POST is not supported by this URL解决

今天写了个非常简单的setvlet想测试些东西,写好了后用postman请求报错,报错内容如下 { "timestamp": 1504170113588, "status": 405, "error": "Method Not Allowed", "message": "HTTP method POST is not supported by this URL", "path&

Appium 使用android_uiautomator定位元素时报错: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource

使用 android_uiautomator 定位元素时(现在用的还不太熟,对于这个方法还需要加深了解)报错: 报错信息:The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource 因为用的不熟,所以也是上网查了好多方法,最后检查代码的时候发现,原来是拼写错误 我将new UiSelect

SSM报错:No converter found for return value of type: class java.util.ArrayList at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverter

我使用的是SSM框架,是在编写测试RESTFUL接口的时候出现, @RequestMapping(value = "/selectAll", method = RequestMethod.GET) @ResponseBody public ResponseEntity<List<User>> selectAll() { List<User> users = this.userService.selectAll(); if (null != users

org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping

配置spring+shiro时,启动tomcat报错异常 严重: Context initialization failedorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of i

HTTP Status 405 - HTTP method POST is not supported by this URL另外一种原因

看了网上的其他解决办法,发现自己的问题并不是那些原因造成的:经过排查还是找到了原因: @WebServlet("/Ce")public class Ce extends HttpServlet {        protected void doGet(HttpServletRequest request, HttpServletResponse response)             throws ServletException, IOException { } protect

Supported method argument types Spring MVC

Supported method argument types The following are the supported method arguments: Request or response objects (Servlet API). Choose any specific request or response type, for example ServletRequest or HttpServletRequest. Session object (Servlet API):

org.springframework.web.HttpRequestMethodNotSupportedException: Request method &#39;PUT&#39; not supported

1:先上控制台报错信息 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported

【Feign调用异常】org.springframework.web.HttpRequestMethodNotSupportedException: Request method &#39;GET&#39; not supported

一.异常场景描述 明明是post请求,为啥到达服务器后就变成了get请求 2019-05-30 18:07:17.055 [http-nio-10650-exec-4] ERROR c.x.xcauto.common.controller.BaseControllerAdvice - 检测到未捕捉异常:IP:192.168.128.1 invoke url:http://172.17.244.170:10650/stock/valid/num/v1 Exception:public class