Home  >  Article  >  Java  >  How SpringBoot accesses jsp pages

How SpringBoot accesses jsp pages

WBOY
WBOYforward
2023-05-28 12:22:062027browse

1. Add pom dependency

First add these two configurations on the basis of the original pom file

<!-- tomcat 的支持.--> 
   <dependency> 
     <groupid>org.springframework.boot</groupid> 
     <artifactid>spring-boot-starter-tomcat</artifactid> 
     <scope>provided</scope> 
   </dependency> 
 
   <dependency> 
     <groupid>org.apache.tomcat.embed</groupid> 
     <artifactid>tomcat-embed-jasper</artifactid> 
     <scope>provided</scope> 
   </dependency>

In fact, according to my own configuration, only configuring tomcat as follows can be successful. Run the project

2. Add relevant configurations in the springBoot configuration file

application.properties

#spring.mvc.view.prefix=/WEB-INF/jsp/ #spring.mvc.view.suffix=.jsp #application.message: Hello Phil 2.application.yml
[html] view plain copy
spring:     
  # HTTP ENCODING 
  http: 
    encoding.charset: UTF-8 
    encoding.enable: true 
    encoding.force: true 
   
  datasource: 
    validation-query: SELECT 1 
    test-on-borrow: true 
     
  mvc: 
    view: 
      prefix: /WEB-INF/jsp/ 
      suffix: .jsp

3. Create a jsp file under web-inf for all jsp folders Folder

How SpringBoot accesses jsp pages

4. Create a transfer method on the backend

@Controller public class F2FController { 
  @RequestMapping(value="/test") 
  public String testF2F() { 
    return "index"; 
     
  }

Debugging is successful, the picture runs as follows

How SpringBoot accesses jsp pages

The above is the detailed content of How SpringBoot accesses jsp pages. For more information, please follow other related articles on the PHP Chinese website!

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