JSP--JSTL(JSP標準標簽庫)
博客說明
文章所涉及的資料來自互聯網整理和個人總結,意在于個人學習和經驗匯總,如有什么地方侵權,請聯系本人洗掉,謝謝!
概念
JavaServer Pages Tag Library JSP標準標簽庫
是由Apache組織提供的開源的免費的jsp標簽
作用
用于簡化和替換jsp頁面上的java代碼
安裝
菜鳥教程檔案地址 https://www.runoob.com/jsp/jsp-jstl.html
下載地址
- 官方下載地址:http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/
- 菜鳥教程下載地址:jakarta-taglibs-standard-1.1.2.zip
下載 jakarta-taglibs-standard-1.1.2.zip 包并解壓,將 jakarta-taglibs-standard-1.1.2/lib/ 下的兩個 jar 檔案:standard.jar 和 jstl.jar 檔案拷貝到 /WEB-INF/lib/ 下,
將 tld 下的需要引入的 tld 檔案復制到 WEB-INF 目錄下,
接下來我們在 web.xml 檔案中添加以下配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/fmt-rt</taglib-uri>
<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core-rt</taglib-uri>
<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/sql-rt</taglib-uri>
<taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/x-rt</taglib-uri>
<taglib-location>/WEB-INF/x-rt.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
使用步驟
-
匯入jstl相關jar包
-
引入標簽庫:taglib指令:
<%@ taglib %> -
使用標簽
常用的JSTL標簽
if--相當于java代碼的if陳述句
-
屬性:
- test 必須屬性,接受boolean運算式
- 如果運算式為true,則顯示if標簽體內容,如果為false,則不顯示標簽體內容
- 一般情況下,test屬性值會結合el運算式一起使用
- test 必須屬性,接受boolean運算式
-
注意:
- c:if標簽沒有else情況,想要else情況,則可以在定義一個c:if標簽
choose--相當于java代碼的switch陳述句
- 使用choose標簽宣告 相當于switch宣告
- 使用when標簽做判斷 相當于case
- 使用otherwise標簽做其他情況的宣告 相當于default
foreach--相當于java代碼的for陳述句
感謝
菜鳥教程
黑馬程式員
萬能的網路
以及勤勞的自己
關注公眾號: 歸子莫,獲取更多的資料,還有更長的學習計劃
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/156169.html
標籤:Java
