1. 安装TomCat
  2. 了解Web项目结构

Untitled

  1. 如何创建Web项目:https://www.bilibili.com/video/BV1Qf4y1T7Hx?
  2. 快速入门Servlet

Untitled

  1. Servlet生命周期
// 当用户第一次访问时调用
public void init(ServletConfig servletConfig) throws ServletException {
    System.out.println("init....");
}
// 当用户访问时调用
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
    System.out.println("service");
}
// 当服务器关闭时调用
public void destroy() {
    System.out.println("destory");
}
  1. 体系结构

Untitled

如果追求更少的代码,只需要继承HttpServlet就行了,下面是简单实例

@WebServlet("/demo3")
public class ServletDemo3 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Get ...");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Post ...");
    }
}
  1. 路由配置

Untitled

  1. Request信息

Untitled

  1. Request不管是GET还是POST都有通用的取值方式

Untitled