[踩坑日记]SpringBoot整合JSP并发布到Linux

1. 配置pom文件

在springboot项目中,如果要访问jsp页面,需要添加以下依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

 <dependency>
	 <groupId>org.apache.tomcat.embed</groupId>
	 <artifactId>tomcat-embed-jasper</artifactId>
</dependency>

<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
</dependency>

<!-- 如果需要开发JSP页面,则还需要引入下面的依赖 -->
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>javax.servlet-api</artifactId>
</dependency>

<!-- 如果编译后,target下classes没有JSP页面,就需要添加下面的依赖 -->
 <resources>
	<!-- 作用是让 src/main/webapp 在编译的时候在 resoureces 路径下也生成webapp文件 -->
	 <resource>
		 <directory>src/main/webapp</directory>
		 <targetPath>META-INF/resources</targetPath>
		 <includes>
			 <include>**/**</include>
		 </includes>
	 </resource>
	 <!-- 防止项目中其他模块找不到yml配置文件问题... -->
	 <resource>
		 <directory>src/main/resources</directory>
		 <includes>
			 <include>**/**</include>
		 </includes>
		 <filtering>false</filtering>
	 </resource>
</resources>

<!-- 如果要打jar包到linux服务器,防止部署到linux服务器后访问JSP页面出现404,就要更改版本 -->
<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<!-- 注意版本1.4.2.RELEASE -->
	<version>1.4.2.RELEASE</version>
</plugin>

2.更改yml文件配置

spring:
 mvc:
  view:
   prefix: /WEB-INFO/jsp/
   suffix: .jsp

3.Controller层

类名上一般我们都会使用 @RestController,应更改为 @Controller

posted @   蟹堡王  阅读(106)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示