关于"HTTP method GET is not supported by this URL"的错误
2008-11-28 17:22
567 查看
写好一个Servlet后访问时抛出"HTTP method GET is not supported by this URL"的错误,先是自己找了一下原因,后又在网络查找相关的原因后找到解决方案。
问题的原因是用Eclipse生成Servlet时,会在doGet和doPost自动添加默认调用父类的构造方法,如下红色标识代码:
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(request, response);
}
这个时候就会有个问题,如果直接调用父类的方法,就相当于父类HttpServlet的doGet或doPost方法覆盖了你重写的方法,而父类HttpServlet的doGet或doPost方法的默认实现是返回状态代码为405的HTTP错误,表示对于指定资源的请求方法不被允许。删除以上代码当中调用父类的方法后问题迎刃而解。
文章出处:http://www.diybl.com/course/3_program/java/javajs/2008923/144667.html
问题的原因是用Eclipse生成Servlet时,会在doGet和doPost自动添加默认调用父类的构造方法,如下红色标识代码:
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(request, response);
}
这个时候就会有个问题,如果直接调用父类的方法,就相当于父类HttpServlet的doGet或doPost方法覆盖了你重写的方法,而父类HttpServlet的doGet或doPost方法的默认实现是返回状态代码为405的HTTP错误,表示对于指定资源的请求方法不被允许。删除以上代码当中调用父类的方法后问题迎刃而解。
文章出处:http://www.diybl.com/course/3_program/java/javajs/2008923/144667.html
相关文章推荐
- HTTP method GET is not supported by this URL"的错误
- servlet错误:HTTP Status 405 - HTTP method GET is not supported by this URL
- servlet错误:HTTP Status 405 - HTTP method GET is not supported by this URL
- 关于Servlet报错:405 HTTP method GET is not supported by this URL问题解决方法
- HTTP method GET is not supported by this URL
- Android异常总结---type Status report message HTTP method GET is not supported by this URL
- 关于解决HTTP Status 405 - HTTP method POST is not supported by this URL方法之一
- Servlet eroor:HTTP method GET is not supported by this URL
- HTTP method GET is not supported by this URL 问题解决
- 405: HTTP method GET is not supported by this URL
- Error: method GET is not supported by this URL 一个关于传统servlet的问题
- HTTP Status 405 - HTTP method GET is not supported by this URL
- HTTP Status 405 - HTTP method GET(POST) is not supported by this URL
- HTTP method GET is not supported by this URL
- HTTP method GET is not supported by this URL
- 当编写Servlet时出现type Status report message HTTP method GET is not supported by this URL description The
- HTTP method GET is not supported by this URL
- HTTP method GET is not supported by this URL
- HTTP Status 405 - HTTP method GET is not supported by this URL
- HTTP Status 405 - HTTP method GET is not supported by this URL