jsp spring boot binding simple example

The introduction of dependence

< Dependency > 
< the groupId > org.springframework.boot </ the groupId > 
< the artifactId > Spring-Boot-Starter-Web </ the artifactId > 
</ dependency > 

<-! JSTL ⼀ a JSP tags is set, it should encapsulates JSP Use Use of nuclear Center Weighted pass function. -> 
< dependency > 
< the groupId > the javax.servlet </ the groupId > 
< the artifactId > JSTL </ the artifactId > 
</ dependency > 

<! - tomcat-embed-jasper主要⽤来⽀持JSP的解析和运⾏。 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>

application.properties front end position and configure the suffix

Here is a pit, note that if the introduction of pom spring-boot-starter-thymeleaf need to be removed, there will be conflict in view of the return time.

That ui file you created in the WEB-INF jsp file storage folder name

# Specify the front-end template file location
spring.mvc.view.prefix: / the WEB-INF / ui /
# specify the front-end template file suffix
spring.mvc.view.suffix: .jsp

In one example, a new jsp ui, test.jsp

<!DOCTYPE html>
<html lang="en">
    <body>
        Time:${time}
        <br>
        Message:${message}
    </body>
</html>

Create a new example controller

@Controller
 public  class TestJspController { 

    @GetMapping ( "/" )
     public String Forward (the Map <String, Object> Model) {
         // Map parameters are passed to the output of the front end 
        model.put ( "Time", new new a Date ()); 
        Model. PUT ( "the Message", "kyoxue" );
         // directly write the name of the JSP file 
        return "the Test" ; 
    } 
}

Right project, maven clean intsall

Right springboot main entrance

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

run as - spring boot app to start the project process

http: // localhost: 8084 / demo / test access

 

Guess you like

Origin www.cnblogs.com/ixixi/p/11687518.html