Springboot Integrating JSP templates
When using JSP in the Springboot framework, the page template uses JSP to introduce related dependencies in POM.XNL, otherwise it cannot be returned to the specified page in the controller
0, build Springboot framework one, add JSP related dependencies are as follows:
<!-- servlet 依赖. --><dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope></dependency><!-- JSTL 依赖. --><dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId></dependency><!-- tomcat 的支持. --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope></dependency><!-- -jasper依赖.(暂时不知道干啥的) --><dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope></dependency>
Second, the configuration file
spring.mvc.view.prefix=/WEB-INF/jspspring.mvc.view.suffix=.jsp
Third, controller
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;import com.xujie.service.CountService;@Controllerpublic class CountController { @Autowired private CountService countService; //跳转页面 @GetMapping("/index") public String goIndex() { return "index"; }}
Iv. writing the index.jsp page under/web-inf/jsp
Slightly
Springboot Integrating JSP templates