Servlet程序处理请求报错-HTTP method GET is not supported by this URL

错误提示:

Servlet程序处理请求报错-HTTP method GET is not supported by this URL_第1张图片

原因:

情况一:继承自HttpServlet的Servlet没有重写对于请求和响应的处理方法:doGet或doPost等方法;

public class ParameterServlet extends HttpServlet {
     
}

情况二:继承自HttpServlet的Servlet重中调用了父类HttpServlet的doGet或doPost

public class ParameterServlet extends HttpServlet {
     
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
     
        super.doGet(req,resp);
    }
}

解决方法:

子类重写doGet或doPost等方法;在你扩展的Servlert中重写doGet或doPost等方法来处理请求和响应时 不要调用父类HttpServlet的doGet或doPost等方法,即去掉super.doGet(request, response)和super.doPost(request, response);

你可能感兴趣的:(JAVA)