springboot项目使用jsp

异常

问题场景

提示:这里简述项目相关背景

springboot课堂学习


问题详情

提示:这里描述项目中遇到的问题

jsp无法访问
报错


原因分析

提示:这里填写问题的分析

没有jsp解析依赖即相关配置


解决方法

提示这里填写改问题的具体解决方案

  1. 导入依赖
<!-- tomcat-jasper -->  
<dependency>  
    <groupId>org.apache.tomcat</groupId>  
    <artifactId>tomcat-jasper</artifactId>  
    <version>9.0.65</version>  
</dependency>
  1. 配置pom文件
<resources>
    <resource>
        <!--源文件位置-->
        <directory>src/main/webapp</directory>
        <!--指定编译到META-INF/resources,该目录不能随便写-->
        <targetPath>META-INF/resources</targetPath>
        <!--指定要把哪些文件编译进去,**表示webapp目录及子目录,*.*表示所有文件-->
        <includes>
            <include>**/*.*</include>
        </includes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*.*</include>
        </includes>
    </resource>
</resources>
  1. 编写application配置文件
spring.mvc.view.prefix=classpath:/
spring.mvc.view.suffix=.jsp  
  1. 在main目录下
  • 创建webapp文件,将jsp文件放在这个目录下
  1. 配置webapp
    webapp配置文件

好吧好复杂,最后我直接使用thymeleaf

posted @ 2022-09-02 12:26  vbig  阅读(46)  评论(0)    收藏  举报

Loading