项目目录截图

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名称 -->
<servlet-name>springMVC</servlet-name>
<!-- servlet 对应的java类 -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 参数设置 -->
<init-param>
<!-- 设置springmvc配置文件的路径 -->
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-config.xml</param-value>
</init-param>
<!-- 设置web应用启动时,该servlet的启动优先级,越小越高-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<!-- 请求对应的servlet名称 -->
<servlet-name>springMVC</servlet-name>
<!-- 监听的范围 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
springmvc-config.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd ">
<!-- 指定扫描的包 -->
<context:component-scan base-package="com.controller"/>
<mvc:annotation-driven/>
</beans>
Controller文件
package com.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* @Author guozhi
* @Date 2019/6/24 22:04
* @Description TODO
*/
@Controller
public class Hello {
@RequestMapping("/")
public ModelAndView hello(){
ModelAndView mv = new ModelAndView();
mv.setViewName("/WEB-INF/welcome.jsp");
return mv;
}
}
welcome.jsp 文件
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
<title>Title</title>
</head>
<body>
hello,world!
</body>
</html>