我有 index.jsp 页面:
</head>
<body>
<form action="HelloWorldServlet" method="post">
<input class="button" type="submit" value="load list" />
</form>
</body>
</head>
我想通过单击“加载列表”按钮来运行我的 HelloWorldServlet。
public class HelloWorldServlet extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
writer.println("Hello, World!");
writer.close();
}
}
但不是“你好,世界!” 消息,它尝试加载http://localhost:8080/HelloWorld/HelloWorldServlet
页面.. 有什么意义?
这是我的 web.xml:
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD
Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>