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": "/vincent/aaa"
}

但是我的控制台还是答应了我的请求内容,百思不得其解,最后发现是因为没有把调用父类的post方法删掉

我的代码如下

@WebServlet(urlPatterns = "/aaa")
public class MyServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {

        super.doGet(request, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        InputStream inputStream = request.getInputStream();
        BufferedReader in=new BufferedReader(new InputStreamReader(request.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String xmlHead = "";
        String xmlContent="";
        String line = null;
        while ((line = in.readLine()) != null) {
            sb.append(line);
        }
        System.out.println(sb);
        super.doPost(request, resp);
    }
}
 super.doPost(request, resp);的源码如下
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String protocol = req.getProtocol();
        String msg = lStrings.getString("http.method_post_not_supported");
        if (protocol.endsWith("1.1")) {
            resp.sendError(405, msg);
        } else {
            resp.sendError(400, msg);
        }

    }

有没有发现,无论你的请求怎样,他都报错的。

时间: 2024-10-10 05:25:43

HTTP method POST is not supported by this URL解决的相关文章

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

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 resp

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

Undefined function or method ' ' for input arguments of type 'double' ---错误解决办法

你如果要使用这个guo.m作为函数进行调用的话,那需要满足以下条件: 1.在guo.m里面要写成function的格式 function [output parmaters]=guo[input parameters] 2.拥有这个function的m文件的文件名要与这个函数名称一致,意思就是文件名要为 guo.m 3.调用这个function的m文件要与guo.m处于同一工作目录下 4.输入输出参数类型要与函数内部要求的类型一致 Undefined function or method ' '

oracle启动报错ORA-00845: MEMORY_TARGET not supported on this system解决办法

oracle启动报错ORA-00845: MEMORY_TARGET not supported on this system 原因可能:ORACLE MEMORY_TARGET参数设置超过了oracle服务器本身内存.或超过了现在服务器空闲内存(就是oracle启动时无法获取设置的内存) eg: oracle version:11gR2 OS version:RedHat 6.4企业版 服务器:虚拟机 分析步骤: 1.查看当前 MEMORY_TARGET参数的值为*.memory_target

laravel项目出现Non-static method Redis::hGet() cannot be called statically的解决方法

早上ytkah在配置laravel项目中出现Non-static method Redis::hGet() cannot be called statically错误提示,很显然这是redis出问题了,search了一下大概是因为PHP自带了redis拓展和predis冲突了导致的.打开composer.json看到确实有一个predis扩展,代码如下.那就好办了!有冲突就要进行调解!为了项目的完整和调试的方便,我们可以把php安装的扩展暂时先停止了,刷新laravel项目果然可以了. "pre

阿里云ECS在CentOS 6.9中使用Nginx提示:nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)的解决方法

说明: 1.[::]:80这个是IPv6的地址. 2.阿里云截至到今天还不支持IPv6. 解决方式: 1.普通解决方式:开启IPv6的支持,不过这个方法在阿里云行不通. vim /etc/nginx/conf.d/default.conf #找到并替换为以下: listen 80; listen [::]:80 ipv6only=on default_server; 2.极端方式:直接屏蔽IPv6,全部服务器都适用. vim /etc/nginx/conf.d/default.conf #找到并

【转】SQLyog SSH 密钥登陆认证提示: No supported authentication methods available 解决方法

问题背景: 问题原因: SQLyog不支持非标准的的私钥格式 解决方案: 使用puttyGen重新导入原来的私钥,然后重新保存成PPK证书文件,最后用SQLyog加载该PPK文件即可. 效果截图: 原文地址:http://www.blogdaren.com/post-1625.html 原文地址:https://www.cnblogs.com/shujuxiong/p/9474843.html