springboot集成jsp.md
李羽秋
2022年01月26日 · 阅读 1,182
springboot集成jsp
1.添加依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
2.添加控制器
@Controller
public class WelcomeController {
@GetMapping("/welcome")
public String welcome(Map<String,Object>model){
model.put("message","welcome to liyuqiu.com");
model.put("author","liyuqiu");
return "welcome";
}
}
3.在src/main下新建webapp/WEB-INF/view文件夹,并建welcome.jsp
<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<head>
<title>spring boot jsp</title>
</head>
<body>
Message: ${message}
author: ${author}
<br/>
<h1>hello!</h1>
</body>
</html>
4.在application对mvc进行配置
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
5.访问结果
分类:
无
标签:
无