springboot 使用JSP
1. 添加依赖
<!-- 引入 springboot 内嵌的 tomcat 对 JSP 的解析包 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- servlet 依赖的 jar 包 start -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
2. 创建 src/main/webapp 文件夹,在 application.properties 文件中配置springMVC 视图展示为 jsp
#前缀
spring.mvc.view.prefix=/
#后缀
spring.mvc.view.suffix=.jsp
3. 在 webapp 下创建 jsp 文件
这里访问页面时会出现如下页面:

产生这个的原因是 idea 没有将jsp文件编译到 classes 中:

在 <build> </build> 中添加配置信息,将 webapp 下的所有文件编译到 META-INF/resources 下:
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
添加后编译结果:

4. 成功访问

SpringBoot集成JSP教程
本文详细介绍如何在SpringBoot项目中使用JSP,包括添加必要依赖、配置视图解析、创建JSP文件及确保正确编译的方法。通过遵循这些步骤,可以实现在SpringBoot框架下部署和运行JSP页面。
848

被折叠的 条评论
为什么被折叠?



