1.引入jsp的集成jar包
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
2.引入jsp运行插件
<build> <!--引入jsp运行插件--> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
插件是必须的,并且要通过插件启动项目,不使用插件,Jsp页面不会被编译,发布。简单说就是:不通过插件启动项目,访问Jsp页面会 404
3.配置视图解析器'
spring:
mvc:
view:
prefix: /
suffix: .jsp
#jsp页面热部署
server:
servlet:
jsp:
init-parameters:
development: true
4.创建webapp目录写入Jsp页面
Jsp相关web资源的位置
-
在main下面创建webapp放置静态资源
-
webapp 下面不要有 web.xml
hello.jsp页面内容
<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<html>
<head>
<meta charset="utf-8">
<%-- 测试${pageContext.request.contextPath} 获取路径能不能使用
--%>
<script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
</head>
<body>
<h1>那天夕阳下的奔跑,是我们无法忘记的青春!</h1>
<script></script>
</body>
</html>
5.通过插件启动项目,即可访问页面
6.访问hello.jsp页面
浏览器访问:http://localhost:8802/hello.jsp