1. 程式人生 > >springboot: 使web項目支持jsp

springboot: 使web項目支持jsp

map utf page 技術分享 set 代碼 推薦 har 圖片

1.springboot為什麽不推薦使用jsp?

  參考地址:https://spring.io/blog/2012/10/30/spring-mvc-from-jsp-and-tiles-to-thymeleaf

  技術分享圖片

2.使用freemark模板引擎有何優勢

  參考地址:http://blog.csdn.net/qq897958555/article/details/53560655

技術分享圖片

3.代碼實現

1).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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.lf</groupId>
  <artifactId>SpringBootInJsp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
  <!-- 繼承 spring-boot-starter-paren -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
    </parent>
    <dependencies>
        <!-- SpringBoot 核心組件 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 添加jsp支持 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
    </dependencies>
</project>

2).IndexController.java

package com.lf.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@EnableAutoConfiguration
public class IndexController { @RequestMapping("index") public String index(){ return "index"; } public static void main(String[] args) { SpringApplication.run(IndexController.class, args); } }

3).index.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> <h1>SpringBoot集成JSP!</h1> </body> </html>

4).測試

技術分享圖片

springboot: 使web項目支持jsp