HTTP method GET is not supported by this URL 问题解决
2013-01-28 15:48
567 查看
package mypack; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HelloServlet extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.doGet(req, resp); String username=req.getParameter("username"); if(username!=null){ username=new String(username.getBytes("ISO-8859-1"),"GB2312"); } if(username==null){ resp.sendError(resp.SC_FORBIDDEN); return; } resp.setContentType("text/html;charset=GB2312"); PrintWriter out=resp.getWriter(); out.println("<html><head><title>,</title></head>"); out.println("<body>"); out.println("hello:"+username); out.println("</body></html>"); System.out.println("before:"+resp.isCommitted()); out.close(); System.out.println("after:"+resp.isCommitted()); } }
此时我们访问:http://localhost:8080/../hello?name=test
就会出现:
HTTP Status 405
- HTTP method GET is not supported by this URL
出现错误的原因:
1,继承HttpServlet的Servlet没有覆写对应请求和响应的处理方法即:doGet或
doPost等方法;默认调用了父类的doGet或doPost等方法;
2, 父类HttpServlet的doGet()或doPost()方法覆盖了你重写的doGet或doPost等
方法;
只要出现以上的情况之一,父类HttpServlet的doGet或doPost等方法的默认实现是
返回状态代码为405的HTTP错误表示:对于指定资源的请求方法不被允许。
解决方法:
1,子类覆写父类的doGet或doPost等方法;
2,在你的Servlert中覆写doGet或doPost等方法来处理请求和响应,不要调用父类
HttpServlet的doGet() 和 doPost()方法,即:
将doGet()方法中的 super.doGet(req, resp);
改为:this.doPost(req , resp) ; 可以解决问题
相关文章推荐
- 关于Servlet报错:405 HTTP method GET is not supported by this URL问题解决方法
- 问题_http 1.1 405 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
- HTTP method GET is not supported by this URL
- 【转】 Servlet eroor:HTTP method GET is not supported by this URL
- J2EE中HTTP method GET/Post is not supported by this URL
- HTTP Status 405 - HTTP method GET is not supported by this URL
- HTTP method GET is not supported by this URL
- Servelet:HTTP method GET is not supported by this URL
- 访问arcgisserver报:HTTP Status 405 - HTTP method GET is not supported by this URL
- HTTP method GET is not supported by this URL
- HTTP method GET 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 eroor: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 详解方案
- HTTP method GET is not supported by this URL
- 405 HTTP method GET is not supported by this URL