HTTP Status 405 - HTTP method GET is not supported by this URL
查看源码可以清晰的看到,这句话是在HttpServlet中的doGet或者doPost方法中返回的,只要没有重新这两个方法,或者直接通过super.doGet()、super.doPost()调用了父类的方法就会出现这个404错误。知道原来就容易解决了,解决方法:
在继承HttpServlet的类中
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp); //应该注释掉 , 错误
PrintWriter out = resp.getWriter();
out.write("this is doGet method");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//super.doPost(req, resp); //应该注释掉 , 正确
PrintWriter out = resp.getWriter();
out.write("this is doPost method");
}