自定义servlet重写doGet或者doPost方法时,405 method not allowed
Posted qf123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义servlet重写doGet或者doPost方法时,405 method not allowed相关的知识,希望对你有一定的参考价值。
自定义servlet
public class TestServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.doGet(req, resp); } }
HttpServlet里的doGet方法是这样定义的
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String protocol = req.getProtocol(); String msg = lStrings.getString("http.method_get_not_supported"); if (protocol.endsWith("1.1")) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); } }
所以重写doGet/doPost方法时,必须先将super.doGet(...)/super.doPost(...)删掉
以上是关于自定义servlet重写doGet或者doPost方法时,405 method not allowed的主要内容,如果未能解决你的问题,请参考以下文章
继承了httpservlet重写service()与重写doget()dopost()区别