Status 405 - HTTP method GET is not supported by this URL
这个恶心的问题终于搞定
tomcat写了个servlet小例子,出现 Status 405 - HTTP method GET is not supported by this URL 错误。
错误的原因就是继承了 HttpServlet 类后得 重写父类的方法,表明看我写的应该也没问题啊?
下面是一开始的源程序:
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class HelloHttp extends HttpServlet{
//处理get请求
//req:获得客户端(浏览器)的信息
//res:用于向客户端返回信息
public void doGet(HttpServletRequest req, ServletResponse res) // 2了啊,这里应该是 “ HttpServletResponse res“
{
//this.doPost(req, res);
try{
PrintWriter pw = res.getWriter();
pw.println("hello,http-doGet");
}
catch(Exception ex){
ex.printStackTrace();
}
}
//处理post请求
public void doPost(HttpServletRequest req, ServletResponse res){ //这里应该是 “ HttpServletResponse res“
this.doGet(req,res);
}
}
没有正确传递参数,就认为我没有复写doGet方法,所以导致了这样的错误~~~~~~~~~~