1.spring boot中配置jsp,但是spring boot官方不推荐使用jsp,因为jsp相对于一些模板引擎,性能都比较低,官方推荐使用thymeleaf,
使用eclipse演示
一、pom.xml中加入tomcat支持和jstl标签库
<!-- tomcat支持 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- jstl标签库 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
二在application.properties文件中配置jsp访问入口
# 页面默认前缀目录
spring.mvc.view.prefix=/WEB-INF/jsp/
# 响应页面默认后缀
spring.mvc.view.suffix=.jsp
三、在 src/main 下面创建 webapp/WEB-INF/jsp 目录用来存放我们的jsp页面。
jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Full Layout - jQuery EasyUI Demo</title>
</head>
<body>
welcome:${sj}
</body>
</html>
四,编写controller测试
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class jspControllere {
@RequestMapping("/jsp")
public String jsp(HttpServletRequest re){
re.getSession().setAttribute("sj", "sj-test-success");
return "index";
}
}
五。启动SpringbootApplication类 运行SpringbootApplication这个类的main方法 run as->java application
或者run as-> maven build 里填写 spring-boot:run 运行