JavaServer Pages(JSP)技術使Web開發人員和設計人員能夠快速開發和輕松維護利用現有業務系統的信息豐富的動態Web頁面。作為Java技術系列的一部分,JSP技術可以快速開發獨立于平臺的基于Web的應用程序。JSP技術將用戶界面與內容生成分開,使設計人員能夠在不改變底層動態內容的情況下更改整體頁面布局。
對開發人員的好處
如果您是熟悉HTML的網頁開發人員或設計人員,則可以:
——以上內容摘自自 Oracle 關于JSP的介紹 鏈接地址:https://www.oracle.com/technetwork/java/overview-138580.html
eclipse創建javaweb項目、雖然現在 JSP基本已經淘汰,但是很多公司的老的項目還是在用 JSP 作為頁面,通過閱讀該篇博客,你將了解到如何在SpringBoot 中快速使用 JSP 簡單操作。
第一步在 pom.xml 添加支持 JSP 視圖的依賴,具體代碼如下:
<!-- 非必選 -->
<dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId>
</dependency>
<!-- Provided 編譯和測試的時候使用-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId><scope>provided</scope>
</dependency>
<!-- 對jsp的支持的依賴 -->
<dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-jasper</artifactId><scope>provided</scope>
</dependency>
第二步在 application.properties 配置文件中添加 JSP 相關配置信息,具體配置信息如下:
server.port=8080
server.servlet.context-path=/sbespring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
第三步創建 src/main/webapp 目錄并在該目錄創建 JSP。
添加JSP文件的路徑位置如下圖所示:
springboot。
JSP 文件內容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>${welcome}
</body>
</html>
第四步創建訪問 JSP 頁面的 Controller。
package cn.lijunkui.controller;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
@RequestMapping()
public class JspController {@RequestMapping("/helloworld")public String toJps(Model model) {model.addAttribute("welcome", "不建議使用jsp");return "welcome";}}
在游覽器輸入訪問 JSP 頁面的 Controller 的 URL:http://localhost:8080/sbe/helloworld 進行測試,測試結果如下:
jsp整合項目實戰,SpringBoot 使用 JSP 步驟如下:
具體代碼示例請查看我的 GitHub 倉庫 springbootexamples 中模塊工程名: spring-boot-2.x-jsp?進行查看
Github:https://github.com/zhuoqianmingyue/springbootexamples
如果您對這些感興趣,歡迎 star、或點贊給予支持!轉發請標明出處!
https://github.com/spring-projects/spring-boot/tree/v2.0.6.RELEASE/spring-boot-samples/spring-boot-sample-web-jsp?
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态