此URL虽然执行doGet,但不支持HTTP方法GET

Ang*_*nes 2 java servlets glassfish-3

public class RoarHistoryUpdate extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException{
        super.doGet(request, response);
        System.out.println("do Get");
        response.setContentType("text/html");
        response.getOutputStream().print("Success");
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的Servlet.它在web.xml中注册如下:

  <servlet>
      <display-name>RoarHistoryUpdateServlet</display-name>
      <servlet-name>RoarHistoryUpdateServlet</servlet-name>
      <servlet-class>de.ulm.uni.vs.avid.roary.servlets.RoarHistoryUpdate</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>RoarHistoryUpdateServlet</servlet-name>
      <url-pattern>/Roary/UpdateServlet</url-pattern>
  </servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

当我转到URL http://localhost:8080/Roary-JSP/Roary/UpdateServlet它说HTTP Status 405 - HTTP method GET is not supported by this URL

有趣的是我得到了do Get登录到我的控制台.所以它实际上找到了doGet- 方法.

我使用的是GlassFish Server开源版3.1.2.2

NIN*_*OOP 8

因为当你做super.doGet(request, response);你的Servlet的doGet()方法,你实际上调用doget()了的HttpServlet类.该Tomcat 7方法的实现如下(可能是类似的实现Glassfish):

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
{
    String protocol = req.getProtocol();
    String msg = lStrings.getString("http.method_get_not_supported");
    if (protocol.endsWith("1.1")) {
        resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
    } else {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
    }
}
Run Code Online (Sandbox Code Playgroud)