標籤:depend 添加 ide 部署 ring work nbsp title star
使用步驟:
1、建立Maven web project項目
2、在pom.xml檔案中添加依賴
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.wyl</groupId> <artifactId>SpringbootJSP</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>SpringbootJSP Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <java.version>1.7</java.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.RELEASE</version> </parent> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 引入tomcat相關依賴 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <!-- tomcat-jasper --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jasper</artifactId> <version>9.0.0.M21</version> </dependency> <!-- 引入servlet依賴 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.0-b07</version> <scope>provided</scope> </dependency> <!-- 引入jstl標籤庫 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- devtools外掛程式,熱部署 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>true</scope> </dependency> </dependencies> <!-- 打包外掛程式 --> <build> <finalName>SpringbootJSP</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork><!-- 熱部署生效必須加 --> </configuration> </plugin> </plugins> </build></project>
3、配置application.properties支援jsp
spring.mvc.view.prefix=/WEB-INF/jsp/spring.mvc.view.suffix=.jsp
4、編寫測試controller
@Controllerpublic class JSPController { @RequestMapping("indexJsp") public String index(Map<String, Object> map){ map.put("hello", "there is jsp"); return "index"; //映射的是/WEB-INF/jsp/index.jsp頁面 }}
5、編寫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><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Insert title here</title></head><body> helloJsp ${hello}</body></html>
Spring Boot入門——使用jsp