springboot默认支持的是Thymeleaf,但是也可以通过配置支持jsp
application.properties
# 页面默认前缀目录spring.mvc.view.prefix=/WEB-INF/jsp/# 响应页面默认后缀spring.mvc.view.suffix=.jsp
pom.xml中添加对jsp的支持
org.springframework.boot spring-boot-starter-web javax.servlet jstl org.apache.tomcat.embed tomcat-embed-jasper org.springframework.boot spring-boot-starter-tomcat
在 src/main 下面创建 webapp/WEB-INF/jsp 目录用来存放我们的jsp页面,目录结构
jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>Insert title here Title ${test}
启动类
@SpringBootApplication@Controllerpublic class Application{ public static void main(String[] args) { SpringApplication.run(Application.class, args); } @RequestMapping("test") public String test(ModelMap map) { map.put("test", "my jsp"); return "test"; }}
浏览器中输入 http://localhost:8080/test