“HTTP method POST is not supported by this URL ”
之前练习的时候,写了个LoginServlet继承的HttpServlet的小例子,运行的时候一直报HTTP method POST is not supported by this URL,代码与报错如下,控制台没有报错: 提示不支持post方法,但是代码里已经设置了post方法,于是有点懵逼,之后查了一下HttpServlet源码里的doPost方法 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是不是1.1的,都是用resp.sendError方法返回一个“http.method_post_not_supported”的错误信息给前台界面。也就是说问题出在super.doPost这里