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

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>

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

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

I am using a GlassFish Server Open Source Edition 3.1.2.2

Cœur
  • 32,421
  • 21
  • 173
  • 232
Angelo.Hannes
  • 1,599
  • 1
  • 15
  • 40

2 Answers2

8

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);
    }
}
NINCOMPOOP
  • 46,742
  • 15
  • 123
  • 158
2

My guess is that it's because of invoking super.doGet(). If you check the source code of HttpServlet, you'll see that it sets this status code on the response. So drop the super call. It's not needed.

NilsH
  • 13,119
  • 4
  • 38
  • 57