2.在父工程中 建一个子工程建一个,然后在子工程中添加 jsp jar servlet依赖 添加 web app 支持junit junit 4.12 org.springframework spring-webmvc 5.1.9.RELEASE javax.servlet servlet-api 2.5 javax.servlet.jsp jsp-api 2.2 javax.servlet jstl 1.2
这是添加 web app
这是在子工程中添加的依赖
3.在子工程中编写一个servlet类,用来提供用户请求javax.servlet servlet-api 2.5 javax.servlet.jsp jsp-api 2.2
public class HelloServlet extends HttpServlet {
public HelloServlet() {
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method = req.getParameter("method");
if (method.equals("add")) {
req.getSession().setAttribute("msg", "执行了add方法");
}
if (method.equals("delete")) {
req.getSession().setAttribute("msg", "执行了delete方法");
}
req.getRequestDispatcher("/WEB-INF/jsp/text.jsp").forward(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
}
4.编写text.jsp,在 WEB-INF 目录中新建一个 text.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
${msg}
5.在web.xml中注册一个servlet
6.配置tomcathello com.yy.servlet.HelloServlet hello /hello
直接蹦出来



