6、创建Servlet测试
在src下新建一个测试用的Servlet,如下图:
重写获取get/post访问的函数
package com.item.test; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet({"/Action"}) public class Action extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("执行过doGet"); doPost(req,resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("执行过doPost"); resp.getWriter().write("<h1>Hello World</h1>"); } }