004--SpringBoot整合JSP

发布时间 2023-07-26 15:23:36作者: Mr_zzl

 

1. SpringBoot整合JSP
参考:SpringBoot | 稀客大大 (heyige.cn)
导入依赖
<!--JSP核心引擎依赖-->
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- JSTL-->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>
创建JSP页面:创建webapp以及WEB-INF去存放JSP页面注:不要忘记在第二幅图填写完成信息后点击应用或直接OK

注:webapp文件上出现小蓝点说明配置成功webapp是web资源的根路径
使用案例:

index.jsp代码:直接生成的;点击webapp,右键新建jsp页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
 <title>Title</title>
</head>
<body>
<h1>index页面</h1>
</body>
</html>

配置视图解析器:

定义测试用接口进行运行测试:-默认是转发到补全后的jsp页面;想要重定向或转发到其他资源路径(非补全)需要在路径前补充"redirect:"和"forward:"如:"redirect:index.jsp"