Spring Boot入門——使用jsp

來源:互聯網
上載者:User

標籤: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.