I. creating a Springboot project
Use http://start.spring.io/to quickly create a springboot project to download and import
Two. Add dependencies
The following dependencies are added to support JSP in Pom.xml:
<!--web-dependent--><dependency> <groupId>org.springframework.boot</groupId> < ;artifactid>spring-boot-starter-web</artifactid></dependency> <!--servlet dependent-< Dependency> <groupId>javax.servlet</groupId> <ARTIFACTID>JAVAX.SERVLET-API&L T;/artifactid> <scope>provided</scope> </dependency><dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId></dependency> & lt;! --Tomcat's support .--><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> </dependency>
Three. Writing a controller
@Controller Public class Logincontroller { @RequestMapping (value= "/login") public String Hello () { return "Login"; } }
Note that at this point the annotations are @controller and cannot be used @restcontroller
Four. Configure the JSP-enabled configuration file application.properties
# #jsp # #spring. Mvc.view.prefix=/web-inf/jsp/spring.mvc.view.suffix=.jsp
Five. Writing JSP pages
Add webapp/web-inf/jsp folder under Project Project Src/main directory, add JSP page
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 " pageencoding=" Utf-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >Hello!!! </body>
Six. Start Project startup class Access Controller path
Description
1,freemarker
2,groovy
3,thymeleaf ( Use this on spring website)
4,velocity
5,spring Boot official does not recommend using JSP, STS created project will have a templates directory under Sec/main/resources, here is let us put the template file, and then did not generate such as Springmvc WebApp directory)
Springboot Project Add JSP support