Servlets 此URL不支持HTTP方法GET

Servlets 此URL不支持HTTP方法GET,servlets,Servlets,我得到了错误,你能帮我吗 servlet public class FirstClass extends HttpServlet { private static final long serialVersionUID = 1L; public void doGet(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException { P

我得到了错误,你能帮我吗

servlet

public class FirstClass extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public void doGet(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        PrintWriter out = response.getWriter();
        out.println("this is a sample");
        out.flush();
    }

    public void doPost(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        PrintWriter out = response.getWriter();
        out.println("this is a sample");
        out.flush();
    }
}
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>hii</display-name>

    <servlet>
        <servlet-name>First</servlet-name>
        <servlet-class>test.FirstClass</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>First</servlet-name>
        <url-pattern>/first.do</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

hii
弗斯特
头等舱
弗斯特
/第一,做什么
index.html
index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <a href="first.do">Click Me</a>
</body>
</html>

在此处插入标题

POST也会失败吗


不应该
test.FirstClass
而是
FirstClass

您的参数设置错误-应该先是请求,然后是响应,如下所示:

public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
因此,目前您实际上并没有覆盖超类方法


这就是注释如此重要的原因——它让您可以在编译时找到类似的bug。如果您用
@Override
修饰您的方法,编译器会发现您试图重写一个不存在的方法签名。

test是定义类的包。嗯,这部分应该可以。我还怀疑Jon提到的呼叫命令。如果呼叫顺序错误,POST将不起作用。是的。。。例如,调用是JavaGoogleAppEngine上的doGet(请求、响应)