Originally intended to continue to write thymeleaf aspects of the content, a look at the content of a lot of, maybe a week can not finish, and from the controller to get value and other content can also be from the online Baidu, so wrote the Springboot integrated JSP. Whether Thymeleaf or JSP is actually the embodiment of layered thought.
First, the introduction of dependency
or use the previous blog's demo, on its basis to modify, this time is the integration of JSP, so the first to introduce the JSP dependency. You need to remove the thymeleaf from the previous blog.
<Dependency> <groupId>Org.apache.tomcat.embed</groupId> <Artifactid>Tomcat-embed-jasper</Artifactid> <Scope>Provided</Scope> </Dependency> <Dependency> <groupId>Javax.servlet</groupId> <Artifactid>Jstl</Artifactid> <Scope>Provided</Scope> </Dependency> <Dependency> <groupId>Javax.servlet</groupId> <Artifactid>Javax.servlet-api</Artifactid> <Scope>Provided</Scope> </Dependency>
Second, create JSP page
Since is the integration JSP, certainly has the JSP page, here I put the JSP page login.jsp under the/demo/src/main/webapp/view. Gets the value of a variable in the controller in the JSP.
<%@ 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 "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>name: ${name}<BR></Body></HTML>
Third, the configuration
Configure the prefix suffix of the view in Application.properties.
spring.mvc.view.prefix=/view/spring.mvc.view.suffix=.jsp
Iv. Creating a Controller
In
PackageCom.example.demo;ImportOrg.springframework.stereotype.Controller;ImportOrg.springframework.ui.Model;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestMethod, @Controller @requestmapping ("/login") Public classLogin {@RequestMapping (value= "/login.do", method =requestmethod.get) PublicString Hello (model model) {Model.addattribute ("Name", "Cuiyw"); return"Login"; }}
V. Testing
Input http://localhost:8080/login/login.do
Springboot the integrated JSP for getting Started