本篇文章给人人带来的内容是关于springboot 2.0.8 跳转jsp页面的要领引见(附代码),有肯定的参考价值,有须要的朋侪能够参考一下,愿望对你有所协助。
这是一篇零丁跳转jsp页面的教程 ,后续会引见html和jsp同时存在的 我临时解释了thymeleaf模版以及设置
1建立目次效果和jsp文件
2设置return 返回模版 及代码
@RequestMapping(value = "/testJsp", produces = "application/json;charset=UTF-8", method = {RequestMethod.POST, RequestMethod.GET}) public String testJsp(Model m, HttpServletRequest request, HttpServletResponse response){ List<Map<String,Object>> list=userService.userQueryAll(); request.setAttribute("list",list); log.info("进入了testJsp要领!"); return "views/testJsp"; }
3.application.yml 文件 设置 thymeleaf 模版参数
spring: dataSource: type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://localhost:3306/db-test?useUnicode=true&characterEncoding=utf8&tinyInt1isBit=false&usessl=false username: root password: 123456 driverClassName: com.mysql.jdbc.Driver mvc: view: #新版本 1.3后能够运用 suffix: .jsp prefix: /WEB-INF/ view: #老版本 1.4后被扬弃 suffix: .jsp prefix: /WEB-INF/
4. pom.xml 文件到场tomcat和jsp支撑 ,假如是有thymeleaf架包的临时解释掉,这里只写jsp跳转( 有thymeleaf架包的时刻return模版会优先跳转html页面)
<!--tomcat支撑--> <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> <!--servlet依靠.--> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency> <!--jsp标签库--> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency>
5. jsp页面这里直接用了EL表达式
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" pageEncoding="UTF-8" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html > <html lang="zh-CN"> <head> <title>Title</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script src="<%=basePath%>static/js/jquery-3.3.1.js" charset="utf-8"></script> </head> <body> <table border="1"> <thead> <tr> <th>序号</th> <th>名字</th> <th>号码</th> <th>建立时候</th> </tr> </thead> <tbody> <c:forEach items="${list}" var="listv" varStatus="status"> <tr> <td>${listv.id}</td> <td>${listv.name}</td> <td>${listv.phone}</td> <td>${listv.create_time}</td> </tr> </c:forEach> </tbody> </table> </body> <script type="text/javascript" charset="utf-8"> </script> </html>
6. Project Structure内里 这个平常是默许设置好了的,假如没有就要加上哦
就这样启动就好了 效果图以下
以上就是springboot 2.0.8 跳转jsp页面的要领引见(附代码)的细致内容,更多请关注ki4网别的相干文章!