可能会帮助你
小服务程序配置
<servlet>
<servlet-name>sampleServlet</servlet-name>
<servlet-class>test.sampleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sampleServlet</servlet-name>
<url-pattern>/sampleServlet/</url-pattern>
</servlet-mapping>
小服务程序代码:
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class sampleServlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException{
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<h1>Hello Servlet Get</h1>");
out.println("</body>");
out.println("</html>");
}
}
JSP代码:
<html>
<body>
<form action="/sampleServlet/" method="GET">
<input type="submit" value="Submit form "/>
</form>
</body>
</html>
您可以单击提交按钮,然后您可以看到 servlet 输出