网站首页 文章专栏 Spring boot 使用 JSP
Spring boot 使用 JSP
编辑时间:2018-07-27 15:33:38.0 作者:听雨·湘潭 浏览量:252

1、在pom.xml文件中配置依赖项

<!--引入Spring Boot内嵌的Tomcat对JSP的解析包-->

<dependency>

    <groupId>org.apache.tomcat.embed</groupId>

    <artifactId>tomcat-embed-jasper</artifactId>

</dependency>

 

<!-- servlet依赖的jar包start -->

<dependency>

	<groupId>javax.servlet</groupId>

	<artifactId>javax.servlet-api</artifactId>

</dependency>

<!-- servlet依赖的jar包start -->



<!-- jsp依赖jar包start -->

<dependency>

	<groupId>javax.servlet.jsp</groupId>

	<artifactId>javax.servlet.jsp-api</artifactId>

	<version>2.3.1</version>

</dependency>

<!-- jsp依赖jar包end -->



<!--jstl标签依赖的jar包start -->

<dependency>

	<groupId>javax.servlet</groupId>

	<artifactId>jstl</artifactId>

</dependency>

<!--jstl标签依赖的jar包end -->

 

2、在application.properties文件配置spring mvc的视图展示为jsp:

spring.mvc.view.prefix=/

spring.mvc.view.suffix=.jsp

 

3、在src/main 下创建一个webapp目录,然后在该目录下新建jsp页面

 

注意,在Idea开发时要在pom.xml的<build>里加上以下配置

<resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/webapp</directory>
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>

 

来说两句吧
最新评论