Servlet HTTP method GET is not supported HTTP 405
2014-10-16 00:00
113 查看
摘要: 写好一个Servlet后访问时抛出"HTTP method GET is not supported by this URL"的错误 HTTP 405
写好一个Servlet后访问时抛出"HTTP method GET is not supported by this URL"的错误,先是自己找了一下原因,后又在网络查找相关的原因后找到解决方案。
问题的原因是用Eclipse生成Servlet时,会在doGet和doPost自动添加默认调用父类的构造方法,如下红色标识代码:
这个时候就会有个问题,如果直接调用父类的方法,就相当于父类HttpServlet的doGet或doPost方法覆盖了你重写的方法,而父类 HttpServlet的doGet或doPost方法的默认实现是返回状态代码为405的HTTP错误,表示对于指定资源的请求方法不被允许。删除以上 代码当中调用父类的方法后问题迎刃而解。
写好一个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错误,表示对于指定资源的请求方法不被允许。删除以上 代码当中调用父类的方法后问题迎刃而解。
相关文章推荐
- typecho安装后登录失败报错 405 Not Allowed nginx/1.10.2
- python网络请求报urllib2.HTTPError: HTTP Error 405: Not Allowed
- HTTP请求错误400、401、402、403、404、405、406、407、412、414、500、501、502解析
- 部署阿里云服务器后访问出现405的访问错误
- springMVC出现HTTP Status 405 - Request method 'GET' not supported错误的解决方法
- 405的第一次出现
- 解决“HTTP/1.1 405 Method not allowed”问题,让静态文件响应POST请求
- 405错误解决办法
- WWDC 2012 Session笔记——405 Modern Objective-C
- HTTP常见错误 400 401 403 404 405 406 407 412 414 500 501 502
- SVN的405错误
- windwos iis 7.5 使用html 报405错误
- 报错:405 Method Not Allowed
- nginx中HTTP/1.1 405 Method not allowed 的解决方法
- Spring MVC拦截405错误
- http 返回码 405 解决方案之一
- web 开发遇到的问题--405 Method Not Allowed
- Codeforces 405 E. Graph Cutting ( DFS )
- HTTP method GET is not supported by this URL 中servlet 的405错误
- SVN-服务器发送了意外的返回值(405 Method Not Allowed),在响应 “MKCOL” 的请求