springboot 2.0.8 jump to jsp page

Keywords: Java JSP Tomcat Spring SpringBoot

Spring boot project creation tutorial https://blog.csdn.net/q18771811872/article/details/88126835

springboot 2.0 jump to html tutorial https://blog.csdn.net/q18771811872/article/details/88312862

jsp+html jump integration https://blog.csdn.net/q18771811872/article/details/88343672

This is a tutorial to jump to jsp page separately. I will introduce html and jsp coexisting later. I temporarily annotated the thmeleaf template and configuration

1 create directory results and jsp files

2. Configure the return return template and code

@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("Entered testJsp Method!");
        return "views/testJsp";
    }

3.application.yml file configuration thmeleaf template parameter

 

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: #Available after new version 1.3
      suffix: .jsp
      prefix: /WEB-INF/
  view: #Old version 1.4 abandoned
    suffix: .jsp
    prefix: /WEB-INF/

4. Add tomcat and jsp support to pom.xml file. If there are temporary comments on the thmeleaf package, only jsp jump is written here (when there are thmeleaf packages, the return template will jump to html page first)

<!--tomcat Support-->
        <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 rely on.-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
        <!--jsp Tag library-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

 

 

5. The JSP page uses the EL expression directly here

<%@ 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>Serial number</th>
        <th>Name</th>
        <th>number</th>
        <th>Creation time</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. In project structure, this is usually configured by default. If not, add it

This is how it starts. The rendering is as follows

Original address https://blog.csdn.net/q18771811872/article/details/88342298

 

springboot 2.0 jump to html tutorial https://blog.csdn.net/q18771811872/article/details/88312862

jsp+html jump integration https://blog.csdn.net/q18771811872/article/details/88343672

Spring boot project creation tutorial https://blog.csdn.net/q18771811872/article/details/88126835

Posted by PickledOnion on Sun, 01 Dec 2019 05:36:45 -0800