0
点赞
收藏
分享

微信扫一扫

Spring Boot 项目 WEB-INF 下 jsp 无法访问,踩坑

眸晓 2022-04-06 阅读 26

具体报错
在这里插入图片描述
项目结构
在这里插入图片描述

首先先确定application.yml配置是否有问题

server:
  port: 8181

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

配置没问题进入下一步

由于 Spring Boot 不推荐使用 jsp,在网上简单查了一下资料,大概就是

既然如此,如果你要使用 JSP ,那么你就打包成 war 包

导入jsp相关依赖坐标

<!--添加tomcat依赖模块.-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
<!-- 添加servlet依赖模块 -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <scope>provided</scope>
</dependency>
<!--jsp页面使用jstl标签-->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>
<!-- 使用jsp引擎,springboot内置tomcat没有此依赖 -->
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>

如果还是没有解决,OK

打包插件版本设置为1.4.2.RELEASE,并且配置好资源目录

表示打包时,将resources目录下的配置文件一并打入。

<build>
    <resources>
        <resource>
            <directory>src/main/webapp</directory>
            <!--这里必须是META-INF/resources-->
            <targetPath>META-INF/resources</targetPath>
            <includes>
                <!--以任意开头点任意结尾的文件-->
                <include>**/**</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

配置完成后,重新加载 maven ,重启项目,再次访问

在这里插入图片描述

举报

相关推荐

0 条评论