首頁  >  文章  >  Java  >  springboot 2.0.8 跳轉jsp頁面的方法介紹(附程式碼)

springboot 2.0.8 跳轉jsp頁面的方法介紹(附程式碼)

不言
不言轉載
2019-03-08 15:55:254012瀏覽

這篇文章帶給大家的內容是關於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> 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頁面)


        
            org.springframework.boot
            spring-boot-starter-tomcat
            provided
        
        
            org.apache.tomcat.embed
            tomcat-embed-jasper
            provided
        
        
        
            javax.servlet
            javax.servlet-api
            4.0.1
            provided
        
        
        
            javax.servlet
            jstl
        

 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 + "/";
%>



    Title
    
    



        
序号 名字 号码 创建时间
${listv.id} ${listv.name} ${listv.phone} ${listv.create_time}

6. Project Structure裡面這個一般是預設配置好了的,如果沒有就要加上哦 

就這樣啟動就行了 效果圖如下

以上是springboot 2.0.8 跳轉jsp頁面的方法介紹(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除