此URL虽然执行doGet

此URL虽然执行doGet

本文介绍了此URL虽然执行doGet,但不支持HTTP方法GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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");
    }
}

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

This is my Servlet. And it is registerd in the web.xml like this:

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

当我转到URL http:// localhost:8080 / Roary -JSP / Roary / UpdateServlet 它说 HTTP状态405 - 此URL不支持HTTP方法GET

When I go to the URL http://localhost:8080/Roary-JSP/Roary/UpdateServlet It says HTTP Status 405 - HTTP method GET is not supported by this URL

有趣的是我将 do get 记录到我的控制台。所以它实际上找到了 doGet -method。

Funny thing is I get the do Get logged to my console. So it actually found the doGet-method.

我使用的是GlassFish Server开源版3.1.2.2

I am using a GlassFish Server Open Source Edition 3.1.2.2

推荐答案

因为当你做 super.doGet(请求,响应); 在你的Servlet的 doGet()方法中,你实际上调用 HttpServlet的 doget() class。该方法的 Tomcat 7 实现如下(可能是 Glassfish 的类似实现):

Because when you do super.doGet(request, response); in your Servlet's doGet() method, you actually call the doget() of the HttpServlet class. The Tomcat 7 implementation of that method is as below (may be a similar implementation exists for 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);
    }
}

这篇关于此URL虽然执行doGet,但不支持HTTP方法GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:04