405: HTTP method GET is not supported by this URL

来源:互联网 发布:数据库用户是什么 编辑:程序博客网 时间:2024/06/06 02:59
【0】README
1)本文旨在解决  405: HTTP method GET is not supported by this URL 的问题;
2)本文raw idea is checkouted from  http://stackoverflow.com/questions/5370633/405-http-method-get-is-not-supported-by-this-url

【1】解决方法:一句话说完,要重写父类的 doGet 和 doPost方法,就不要调用 super.doGet() 和 super.doPost()方法;如下:
public class SampleServlet extends HttpServlet {       private static final long serialVersionUID = -5404916983906926869L;    /* @Override    public void init() throws ServletException {        super.init();    }*/       @Override    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {         // super.doGet(request, response);  // should be commented out               response.setContentType("text/plain");        PrintWriter out = response.getWriter();        System.out.println("console info: 请求SampleServlet GET Method");        out.println("GET Method: these info are transmitted into client.");        out.flush();    }     @Override    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // super.doPost(request, response); // should be commented out               response.setContentType("text/plain");        PrintWriter out = response.getWriter();        System.out.println("请求SampleServlet GET Method");        out.print("请求SampleServlet POST Method");        out.flush();    }     /*@Override    public void destroy() {        super.destroy();    }*/}


0 0
原创粉丝点击