Java 此URL不支持HTTP方法GET,尽管它执行doGet
这是我的Servlet。它在web.xml中的注册方式如下:Java 此URL不支持HTTP方法GET,尽管它执行doGet,java,servlets,glassfish-3,Java,Servlets,Glassfish 3,这是我的Servlet。它在web.xml中的注册方式如下: public class RoarHistoryUpdate extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ super.doGet(request, respon
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");
}
}
RoarHistoryUpdateServlet
RoarHistoryUpdateServlet
de.ulm.uni.vs.avid.roary.servlets.RoarHistoryUpdate
RoarHistoryUpdateServlet
/Roary/UpdateServlet
当我转到URLhttp://localhost:8080/Roary-JSP/Roary/UpdateServlet
它说HTTP状态405-此URL不支持HTTP方法GET
有趣的是,我将确实得到登录到我的控制台。因此它实际上找到了doGet
-方法
我使用的是GlassFish服务器开源版本3.1.2.2,因为当您执行super.doGet(请求、响应)时
在Servlet的doGet()
方法中,您实际上调用了HttpServlet
类的doGet()
。该方法的Tomcat 7
实现如下所示(对于Glassfish
,可能存在类似的实现):
我猜这是因为调用了super.doGet()
。如果您检查HttpServlet
的源代码,您将看到它在响应上设置了此状态代码。所以放下超级电话。不需要了。是的,就是这样。谢谢请把它标为答案,因为它对你有帮助。
<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>
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);
}
}