SpringBoot跳转jsp
程序员文章站
2022-05-26 10:00:56
...
springboot项目创建之后
一、pom加入依赖
<!-- 添加 jsp 依赖-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- 添加 JSTL 支持 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
二、jsp跳转默认位置src/main/webapp,所以创建webapp目录,注意层级
三、创建controller
package com.example.export.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* TODO
*
* @author <a href="">chenhao</a>
* @version 1.0.0
* @since 1.0.0
*
* Created at 2018/4/10
*/
@Controller
public class HelloController {
@RequestMapping(value = "/hello")
public String HelloWord(){
return "hello.jsp";
}
}
那么就完成了,访问http://localhost:8080/hello 即可展示jsp内容
加上视图解析器(有需求即可加上):
server:
port: 8080
#spring:
# mvc:
# view:
# prefix: /WEB-INF/jsp/
# suffix: .jsp