HTTP method POST was not supported by this URL incorrect solution

Source: Internet
Author: User

Write a simple servlet, after the submission of the servlet will always report HTTP method The POST is not supported by the URL error, I was puzzled, in the BS development process has not encountered this kind of error, Baidu once also did not solve the problem, finally found in the rewrite of the Dopost added a statement super.dopost led, but under the Tomcat had to under the original code, After opening the Javax.servlet.http.HttpServlet.java file, the Dopost method for the superclass is found as follows:

     protected void DoPost (HttpServletRequest req, HttpServletResponse resp)
  & nbsp;      throws Servletexception, IOException
     {
          String protocol = Req.getprotocol ();
         String msg = lstrings.getstring ("Http.method_post_not_ Supported ");
         if (Protocol.endswith ("1.1")) {
              Resp.senderror (httpservletresponse.sc_method_not_allowed, msg);
        } else {
              Resp.senderror (Httpservletresponse.sc_bad_request, msg);
        }
    }

In other words, regardless of your HTTP is not 1.1, are using the Resp.senderror method to return a http.method_post_not_supported error message to the front interface, put me in good pain, strongly condemn the Tomcat code comments, Should be noted do not add super.dopost, can not always let us see your source code it. hehe.


Source: http://hi.baidu.com/winlei/item/cdd3000da3224eca9057181b

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.