配置依赖
<!--引入springboot内嵌Tomcat对jsp的解析包,不添加解析不了-->
<!--仅仅只是展示jsp页面,只添以下一个依赖-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!--
Springboot项目默认推荐的前端引擎是thymeleaf,而且我们要使用springboot集成
jsp,手动指定jsp最后编译的路径而且springboot集成jsp编译jsp的路径是springboot
规定好的位置META-INF/resources
-->
<resources>
<resource>
<!--源文件-->
<directory>src/main/webapp</directory>
<!--指定编译到META-INF/resources-->
<targetPath>META-INF/resources</targetPath>
<!--指定编译文件夹中的哪个资源要编译-->
<includes>
<include>*.*</include>
</includes>
</resource>
</resources>
配置视图解析器
#配置视图解析器
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
IndexController.class
@Controller
public class IndexController {
@RequestMapping("/say")
public ModelAndView say(){
ModelAndView mv=new ModelAndView();
mv.addObject("message","HelloSpringboot");
mv.setViewName("say");
return mv;
}
}
say.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>${message}</h1>
</body>
</html>