pom.xml中添加:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- <scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- 如果用c标签,需要引入这个 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

还有一个可加的:

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.0.28</version>
<scope>provided</scope>
</dependency>

application.properties中添加:

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

代码结构如图:

springboot访问WEB-INF下的jsp页面_tomcat


controller代码:

@Controller
public class JspController {
@RequestMapping("/index2")
public String index2(){
return "index2";
}
}

启动application之后,输入路径即可:

http://localhost:8080/index2

注意:jsp文件不能放在templates下。
因为默认会去webapp下查找。