美文网首页
Springboot使用jsp作为view视图

Springboot使用jsp作为view视图

作者: 淡定丶说的是 | 来源:发表于2017-06-03 22:31 被阅读282次

配置springboot支持jsp

添加关于jsp相关的maven支持

<!--springboot tomcat jsp支持开启-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <!--servlet支持开启-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <!--jstl支持开启-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

配置视图

  • 要想让spring-boot支持JSP,需要将项目打成war包,所以需要在pom.xml中将jar改成war
  • 在main目录下面依次建立文件夹,webapp/WEB-INF,就这样写死
  • 打开springboot配置文件application.yml,添加下面的视图配置
spring:
    mvc:
      view:
        prefix: /WEB-INF/
        suffix: .jsp

然后将jsp文件放在WEB-INF这个目录下面就可以了

好了,下面我们建立相应的IndexController和index.jsp测试一下了~

相关文章

网友评论

      本文标题:Springboot使用jsp作为view视图

      本文链接:https://www.haomeiwen.com/subject/gywmfxtx.html