Home  >  Article  >  Java  >  Introduction to the method of integrating JSP with spring boot (code example)

Introduction to the method of integrating JSP with spring boot (code example)

不言
不言forward
2019-01-30 11:16:253007browse

This article brings you an introduction to the method of integrating JSP with spring boot (code examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

I remember that when I first started integrating jsp with the spring boot project, I found some information on the Internet. However, most of the information was only part of it, either not valid or taken out of context. Especially the articles in csdn are full of cheaters and messy ones. That's why I decided to write some blogs to record the new technologies used in work and study, the pitfalls I have encountered, the technical points and knowledge points I have used before, so that it can be convenient for others. Spring boot simplifies and integrates spring and spring mvc on the original basis, and has made many changes. Different from previous web projects, jsp can be integrated, but it uses templates by default, so integrating jsp still requires a lot of work.

Before reading this blog, please read my spring boot common notes

If the spring boot project is to be deployed to tomcat on Linux, please read my spring boot tomcat deployment

When importing the maven dependency of the corresponding jar package, pay attention to its corresponding version (for example: spring boot and the corresponding version in cba97bffed69576781755455c6f1e41337fea447ce86e32369605f68ca6046c0)

The jar in the dependency When to use

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
# provided表明该包只在编译和测试的时候用
<scope>provided</scope>
</dependency>

In addition to the necessary jars and plug-ins, you also need to import the spring-boot-maven-plugin plug-in

 <build>
        <finalName>${project.name}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

application.properties:

## JSP配置
# 页面默认前缀
spring.mvc.view.prefix=/WEB-INF/view/
# 响应页面默认后缀
spring.mvc.view.suffix=.jsp

#关闭默认模板引擎
spring.thymeleaf.cache=false
spring.thymeleaf.enabled=false

In the main directory (Same level as the java and resource directories) Create a webapp directory. The webapp is equivalent to the WebContent directory in the web project

When you start the project, you can deploy it Start it in tomcat like a web project, or you can use the main method to start it automatically. If there is a problem and cannot be started, use the spring-boot-maven-plugin plug-in to start

The above is the detailed content of Introduction to the method of integrating JSP with spring boot (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete