SpringBoot-添加对jsp的支持

操作系统:Windows10 1909

IDE:IntelliJ Idea v2019.3.3

SpringBoot:2.2.6

Maven:3.6.1

步骤:

1、添加maven依赖

<!-- 使用jsp引擎,springboot内置tomcat没有此依赖 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

2、添加webapp目录

  作用与普通web工程相同,此处该目录仅用来存放jsp文件

3、添加jsp编译路径配置

<build>
<resources>
<!--springboot使用的web资源要编译到META-INF/resources-->
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</build>

4、直接访问即可

  比如我的项目访问路径是“/springboot/web”,jsp名为“test.jsp”

  直接访问地址:http://localhost/springboot/web/test.jsp 就可以

 

ps:网上很多教程都是讲的如何通过controller访问,但是直接访问需要配置servlet,但我没发现有配置servlet这个需要

  如果有问题的话可以留言或者私信讨论

posted @ 2020-04-26 10:36  Git_Bug  阅读(241)  评论(0)    收藏  举报