文章目录
- 1.SpringMVC执行流程
-
- 2.安装Tomcat
- 1.下载
- 2.解压到任意目录即可
- 3.IDEA配置Tomcat
-
- 3.创建maven项目
- 1.创建sun-springmvc模块(webapp)
- 2.查看是否被父模块管理
- 3.pom.xml引入依赖
- 4.目录
- 5.SunDispatcherServlet.java
- 6.web.xml 配置中央控制器
- 7.启动Tomcat测试访问
1.SpringMVC执行流程
1.基础流程图
2.详细流程图
2.安装Tomcat
1.下载
2.解压到任意目录即可
3.IDEA配置Tomcat
1.配置Deloyment
2.配置Server
3.创建maven项目
1.创建sun-springmvc模块(webapp)
2.查看是否被父模块管理
3.pom.xml引入依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.sunxiansheng</groupId><artifactId>core_mechanisms</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>sun-springmvc</artifactId><packaging>war</packaging><name>sun-springmvc Maven Webapp</name><url>http://maven.apache.org</url><dependencies><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version><scope>provided</scope></dependency><dependency><groupId>dom4j</groupId><artifactId>dom4j</artifactId><version>1.6.1</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.5</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId><version>2.4.2</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies><build><finalName>sun-springmvc</finalName></build>
</project>
4.目录
5.SunDispatcherServlet.java
package com.sunxiansheng.springmvc.servlet;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class SunDispatcherServlet extends HttpServlet {private static final Logger log = LoggerFactory.getLogger(SunDispatcherServlet.class);@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {log.info("SunDispatcherServlet doGet");}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {log.info("SunDispatcherServlet doPost");}}
6.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><display-name>Archetype Created Web Application</display-name><servlet><servlet-name>SunDispatcherServlet</servlet-name><servlet-class>com.sunxiansheng.springmvc.servlet.SunDispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:sunspringmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>SunDispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>
7.启动Tomcat测试访问