springboot整合常用组件和服务【2】springboot支持jsp

springboot建议使用模板技术如freemarker、thymleaf,不建议使用jsp,但是它支持使用jsp。本文将阐述springboot中如何支持jsp。

1、环境约束

  • win10 64位操作系统
  • idea2018.1.5
  • maven-3.0.5
  • jdk-8u162-windows-x64

2、前提约束

完成springboot创建web项目 https://www.jianshu.com/p/de979f53ad80

3、修改pom.xml

加入依赖如下:

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

加入resources如下:

        <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>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
        </resources>

4、在src/main当中创建webapp,并加入项目

具体操作如下:

创建webapp

5、在src/main/webapp下创建index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    this is jsp page in webapp
</body>
</html>

6、启动项目

启动项目

7、测试

打开浏览器,输入http://localhost:8888/index.jsp。具体操作如下:

测试


至此,我们完成了在springboot中支持jsp页面,并完成了测试。

猜你喜欢

转载自blog.csdn.net/qq_41717874/article/details/88971959
今日推荐