分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

HTTP method POST is not supported by this URL解决

发布时间:2023-09-06 01:07责任编辑:董明明关键词:POST

今天写了个非常简单的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); ???????} ???}

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

HTTP method POST is not supported by this URL解决

原文地址:http://www.cnblogs.com/vincentren/p/7459312.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved