spring-boot 配置jsp

sring-boot 集成  jspjava

  spring-boot默认使用的页面展现并非jsp,若想要在项目中使用jsp还须要配置一番。web

  虽然spring-boot中也默认配置了InternalResourceViewResolver,可是这个视图解析器并无解析jsp的功能,它只是把解析工做交给容器。而容器中又是调用JspServlet进行jsp解析的,全部这里咱们须要引入JspServlet所在的jar包( tomcat-embed-jasper-xxx.jar)。一般和jsp配合使用的还有jstl.jar,和standar.jarspring

  

        <!-- jsp 解析 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <!-- jstl标签库 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <!-- 标签库引入 -->
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
        </dependency>

 

  

 

  这时虽然spring-boot能够解析jsp了可是他还须要知道怎么去找到jsp,因此这里还须要配置一下jsp查找路径,即咱们熟悉的spring-mvc中的prefix和suffix配置。apache

          spring.mvc.view.prefix=/WEB-INF/views/
          spring.mvc.view.suffix=.jsp

  而spring-boot中默认是没有/WEB-INF文件夹的因此咱们须要本身建立。咱们须要在/src/main目录下建立一个和/java,/resources平级的目录/webapp。而后再webapp下面建立WEB-INF/views。咱们把jsp放入views中,这样spring-boot就能够顺利的查找到jsp了。spring-mvc

 

  然而当咱们运行程序的时候,spring-boot并不会把咱们建立的webapp下的文件打包进去,咱们还须要再maven中配置一下项目的路径,只有这样spring-boot才会把咱们建立的文件夹打包进去,这样咱们能够顺利的访问到jsp了。tomcat

        <resources>
            <resource>
                <directory>src/main/webapp</directory>
                <!--注意这次必需要放在此目录下才能被访问到 -->
                    <targetPath>/</targetPath>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
        </resources>        
相关文章
相关标签/搜索