第一步:添加 jsp相关依赖
<!-- servlet,jsp -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- tomcat 的支持. -->
<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>
<scope>provided</scope>
</dependency>
第二步:配置视图解析器
#views
spring.mvc.view.prefix= /WEB-INF/views/
spring.mvc.view.suffix= .jsp
在main下面创建webapp/WEB-INF/views/
第三步:Controller实现
@Controller
public class JspController {
@RequestMapping("/index")
public String index(HttpServletResponse response,HttpServletRequest request ){
request.setAttribute("msg", "这是springboot集成jsp");
return "index";//访问的是视图解析器的jsp
// return "forward:/index.jsp";//访问的是外部的jsp
}
}