Spring Boot集成jsp页面
1.指定存放web资源目录
集成jsp页面需要在src/main下创建webapp目录以存放jsp文件,须在Project Structor中指定该目录为资源目录
二.使用物理视图访问jsp
1.引入jasper依赖
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
2.注册资源目录
<build>
<!-- 注册资源目录 -->
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</build>
3.创建jsp和controller看效果
新建一个index.jsp页面
<%--
Created by IntelliJ IDEA.
User: zhouzhongyi
Date: 2021-09-06
Time: 9:50
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="UTF-8">
<title>This my index</title>
</head>
<body>
<form action="test/myinfo" method="post">
姓名:<input type="text" id="name" name="name"/> <br>
年龄:<input type="text" id="age" name = "age"/>
<input type="submit" value="提交">
</form>
</body>
</html>
新建一个myinfo.jsp页面
<%--
Created by IntelliJ IDEA.
User: zhouzhongyi
Date: 2021-09-06
Time: 10:09
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="UTF-8">
<title>My Info</title>
</head>
<body>
name = ${name}<br>
age = ${age}
</body>
</html>
controller控制器
启动执行效果
三、使用逻辑视图访问jsp
yml中需增加视图配置
controller只需更改返回的信息为如下图即可