springboot: 使web项目支持jsp
Posted 拾柴小斯
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot: 使web项目支持jsp相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot IDEA 搭建 springboot 项目 + jsp 页面模板