spring boot(嵌入式tomcat)支持jstl

1月 5, 2022 |

1、添加jstl依赖

<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
	<version>1.2</version>
</dependency>
<dependency>
	<groupId>org.apache.tomcat.embed</groupId>
	<artifactId>tomcat-embed-jasper</artifactId>
	<version>9.0.56</version>
	<scope>provided</scope>
</dependency>

2、application.yml中指定

spring.mvc.view.prefix = /jsp/
spring.mvc.view.suffix = .jsp

3、项目<packaging>war</packaging>

4、多模块项目请正确指定working directory
working directory指向war所在的模块,也就是web.xml所在的模块。
参考spring DocumentRoot文件,默认从[working directory]目录下{ "src/main/webapp", "public", "static" }目录读取jsp文件

当项目打成war包后,spring 通过定位WEB-INF目录来确定存放jsp文件的根目录,参考DocumentRoot.getExplodedWarFileDocumentRoo方法

Posted in: spring practise

Comments are closed.