Springboot使用Jsp
maven依赖
1 <!-- 部署tomcat,排除冲突--> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-tomcat</artifactId> 5 <scope>provided</scope> 6 </dependency> 7 <!-- servlet依赖 --> 8 <dependency> 9 <groupId>javax.servlet</groupId> 10 <artifactId>javax.servlet-api</artifactId> 11 </dependency> 12 <dependency> 13 <groupId>javax.servlet</groupId> 14 <artifactId>jstl</artifactId> 15 </dependency> 16 <!-- tomcat的支持--> 17 <dependency> 18 <groupId>org.apache.tomcat.embed</groupId> 19 <artifactId>tomcat-embed-jasper</artifactId> 20 </dependency>
创建与java、resources同级的webapp,并设置了context
application.properties文件
/WEB-INF/jsp/在webapp下
spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp
注意:
- 项目中千万不要有thymleaf依赖不然头发掉光了,都不会走jsp,会默认走thymleaf的解析器
- 多模块项目访问404,参照我另一篇文章