`
qingtianzhu
  • 浏览: 15165 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

HTTP method GET is not supported by this URL

    博客分类:
  • JSP
阅读更多
public class Servlet2 extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, 
      HttpServletResponse resp )throws ServletException, IOException {
	super.doGet(req, resp);
  }
	
  @Override
  protected void doPost(HttpServletRequest req, 
       HttpServletResponse resp)throws ServletException, IOException {
	//设置响应类型
	resp.setContentType("text/html;charset=utf-8") ;
	//从响应实例中获取打印流
	PrintWriter out = resp.getWriter() ;
	out.println("<html>") ;
	out.println("<head><title>servlet2</title></head>") ;
	out.println("<body>") ;
	out.println("从Servlet2中获取请求参数name的值:") ;
	out.println(req.getParameter("name")) ;
	out.println("</body>") ;
	out.println("</html>") ;
  }
}

此时我们访问:http://localhost:8000/../servlet2?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) ; 可以解决问题。
1
1
分享到:
评论
1 楼 mercyblitz 2010-08-08  
楼主覆盖一下service方法就行了,这样不论是POST、GET、TRACE、PUT、DELETE等HTTP标准方法都会被采纳。

相关推荐

    java解决405 - HTTP method GET is not supported by this URL

    当您遇到"405 - HTTP method GET is not supported by this URL"这样的问题时,通常意味着您的服务器端代码没有正确处理GET请求,或者请求被误定向到了一个不期望GET方法的Servlet。 首先,我们需要理解HTTP协议中...

    Http-servlet请求源码

    本文将深入探讨HTTP Servlet请求的源码实现,并针对"HTTP method GET is not supported by this URL"这一常见错误进行分析和解决。 首先,让我们理解HTTP Servlet的工作原理。每当一个HTTP请求到达Web服务器时,...

    Senfore_DragDrop_v4.1

    This is caused by a quirk in WinZip; Apparently WinZip doesn't like IDataObject.GetData to be called before IDropTarget.Drop is called. ------------------------------------------- 5. Support and ...

    servlet2.4doc

    Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. encodeUrl(String) - Method in class javax.servlet....

    JSP Simple Examples

    In this program we are going to know how the server determines whether the password entered by the user is correct or not. This whole process is controlled on the server side. Multiple forms in jsp ...

    php.ini-development

    documents, however this remains supported for backward compatibility reasons. ; Note that this directive does not control the , which can be ; used regardless of this directive. ; Default Value: On ;...

    asp.net mvc

    This is a Release Candidate (RC) release and is not officially supported. If you have questions about working with this release, post them to the ASP.NET MVC forum (http://forums.asp.net/1146.aspx), ...

    Java邮件开发Fundamentals of the JavaMail API

    the ability to see how many new mail messages they have, are not supported by POP at all. These capabilities are built into programs like Eudora or Microsoft Outlook, which remember things like the ...

    hls.min.js

    e.a=a},function(t,e){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(t){return"function"==typeof t}function a(t){return"number"==typeof t}function n...

    Bochs - The cross platform IA-32 (x86) emulator

    - new hdimage method get_capabilities() that can return special flags - vmware3, vmware4 and vvfat classes now return HDIMAGE_HAS_GEOMETRY flag - other disk image modes by default return HDIMAGE_...

    PHP获取所在城市JS方法,开箱即用

    console.log('Geolocation is not supported by this browser.'); } ``` 这段代码首先检查浏览器是否支持Geolocation API,如果支持,则调用`getCurrentPosition`获取位置信息,然后通过`fetch`函数向服务器发送...

    EurekaLog_7.5.0.0_Enterprise

    Later is supported when map2dbg.exe tool is placed in \Bin folder of EurekaLog installation (separate download is required) 5)....Added: Exception2HRESULT in EAppDLL to simplify developing DLLs with ...

    hibernate.properties

    ## Derby (not supported!) #hibernate.dialect org.hibernate.dialect.DerbyDialect #hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver #hibernate.connection.username #hibernate....

    ZendFramework中文文档

    14.1.3. 使用静态 get() 方法 14.2. 标准过滤器类 14.2.1. Alnum 14.2.2. Alpha 14.2.3. BaseName 14.2.4. Digits 14.2.5. Dir 14.2.6. HtmlEntities 14.2.7. Int 14.2.8. RealPath 14.2.9. StringToLower...

Global site tag (gtag.js) - Google Analytics