`

HTTP method GET is not supported by this URL 405

阅读更多

Servlet  eroor:HTTP method GET is not supported by this URL

错误提示:

 type: Status report

message: HTTP method GET is not supported by this URL

description: The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

原因:

1,继承自HttpServlet的Servlet没有重写对于请求和响应的处理方法:doGet或doPost等方法;默认调用父类的doGet或doPost等方法;

2,父类HttpServlet的doGet或doPost等方法覆盖了你重写的doGet或doPost等方法;

不管是1或2,父类HttpServlet的doGet或doPost等方法的默认实现是返回状态代码为405的HTTP错误表示对于指定资源的请求方法不被允许。

解决方法:

1,子类重写doGet或doPost等方法;

      2,在你扩展的Servlert中重写doGet或doPost等方法来处理请求和响应时 不要调用父类HttpServlet的doGet或doPost等方法,即去掉super.doGet(request, response)和super.doPost(request, response); 

     web.config的配置

<servlet>

<servlet-name>com.panjun.servlets.HelloWorld</servlet-name>

<servlet-class>com.panjun.servlets.HelloWorld</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>com.panjun.servlets.HelloWorld</servlet-name>

<url-pattern>/HelloWorld</url-pattern>

</servlet-mapping>

 

Servlet代码:

package com.panjun.servlets;




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 HelloWorld extends HttpServlet {




/* (non-Javadoc)

* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

*/

@Override

protected void doGet(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException {

// TODO Auto-generated method stub

//super.doGet(req, resp);

resp.setContentType("text/html");

PrintWriter out = resp.getWriter();

out.println("<HTML>");

out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");

out.println("<BODY>");

out.println("<BIG>Hello World</BIG>");

out.println("</BODY></HTML>");

}




public void doPost(HttpServletRequest req, HttpServletResponse res)

throws ServletException, IOException {

doGet(req, res);

}

}

 

分享到:
评论

相关推荐

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

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

    Http-servlet请求源码

    Http-servlet请求完整代码(client-service),以及servlet的“HTTP method GET is not supported by this URL”错误处理

    http请求405错误方法不被允许的解决 (Method not allowed)

    主要介绍了http请求405错误方法不被允许的解决 (Method not allowed),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

    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 ...

    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_...

    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...

    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