The 405 error of the servlet in the HTTP method get are not supported by this URL

Source: Internet
Author: User

Problem Analysis:

1, the servlet that inherits from HttpServlet does not rewrite methods such as Doget or dopost, and methods such as Doget or Dopost of the parent class are invoked by default;

2, the parent class HttpServlet doget or Dopost and so on the method overrides you to rewrite Doget or the dopost and so on method;

Whether it is 1 or 2, the default implementation of methods such as the Doget or dopost of the parent class HttpServlet is that an HTTP error that returns a status code of 405 indicates that the request method for the specified resource is not allowed.

Solution:
1, subclasses rewrite Doget or Dopost methods;

2, when you rewrite Doget or dopost in your extended servlert to handle requests and responses, do not invoke the Doget or Dopost methods of the parent class HttpServlet, that is, remove super.doget (request, response) and Super.dopost (request, response);

public class Testservlet extends HttpServlet {

/**    
 * Serialversionuid:todo (describe what this variable means in one sentence) *    
 * @since Ver 1.1/    

private static final long Serialversionuid = 1L;

@Override
protected void doget (HttpServletRequest req, HttpServletResponse resp)
        throws Servletexception, IOException {
       printwriter out=resp.getwriter ();
       Out.println ("Hello,fucilu");
}

}

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.