码迷,mamicode.com
首页 > 编程语言 > 详细

springboot: 使web项目支持jsp

时间:2018-01-24 20:03:47      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:ann   继承   article   tin   16px   spring   import   asp   tty   

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

标签:ann   继承   article   tin   16px   spring   import   asp   tty   

原文地址:https://www.cnblogs.com/leifei/p/8342945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!