zoukankan      html  css  js  c++  java
  • 自定义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(...)删掉

  • 相关阅读:
    技巧使用
    一些常用的安装包可选安装组件
    php ob_flush与flush的作用
    HTML5 localStorage本地存储
    php clearstatcache
    iconv
    Mysql数字类型转换函数
    POJ
    POJ
    POJ
  • 原文地址:https://www.cnblogs.com/qf123/p/10114012.html
Copyright © 2011-2022 走看看