此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中注册,如下所示:
RoarHistoryUpdateServlet RoarHistoryUpdateServlet de.ulm.uni.vs.avid.roary.servlets.RoarHistoryUpdate RoarHistoryUpdateServlet /Roary/UpdateServlet
当我转到URL http://localhost:8080/Roary-JSP/Roary/UpdateServlet
它说HTTP Status 405 - HTTP method GET is not supported by this URL
有趣的是我得到了记录到我的控制台。 所以它实际上找到了doGet
-method。
我使用的是GlassFish Server开源版3.1.2.2
因为当你做super.doGet(request, response);
在你的Servlet的doGet()
方法中,你实际上调用了HttpServlet
类的doget()
。 该方法的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); } }
我的猜测是因为调用了super.doGet()
。 如果检查HttpServlet
的源代码,您将看到它在响应上设置此状态代码。 所以放弃超级电话。 这不是必需的。