<!--引入springboot 內嵌tomcat對jsp的解析包--> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <!--servlet依賴jar--> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <!--jsp依賴jar--> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> </dependency> <!--Jstl標籤依賴的jar包start--> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency>
build下添加html
<resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </resource> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/*.*</include> </includes> </resource> </resources>
spring.mvc.view.prefix=/ spring.mvc.view.suffix=.jsp
默認在webapp下java
<%@ page 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>測試頁面4</title> </head> <body> ${haha} </body> </html>
@Controller public class Test1Controller { @RequestMapping(value = "/test") public String test1(Model model){ model.addAttribute("haha","個人天"); return "index"; } }
http://localhost:8080/testweb