c:out
c:out 標籤爲輸出一些常量或變量的值
屬性 | 作用 |
---|---|
value | 必選 顯示的內容,可以爲字符常量,也可以爲el 表達式 |
default | 可選 當el 表達式的值爲null 的話,則會顯示爲空 |
escapeXML | 可選 默認值 true 解析符號轉義 flase 爲解析 |
測試
<c:out value="< value >" default="no value" escapeXml="false"></c:out>
結果:<value>
<c:out value="< value >" default="no value" escapeXml="true"></c:out>
結果:<< value >>
c:set
創建一個變量或者修改一個bean 或 map 對象的屬性值
屬性 | 作用 |
---|---|
value | 必選 修改的對象值、或創建變量的值 |
var | 可選 創建變量的變量名 |
scope | 可選 創建的變量 所在的內置對象名稱page、request、session、application |
target | 可選 修改的bean 對象或者map對象 |
property | 修改的屬性 |
創建變量
<c:set var="test1" value="i am test1 var value" scope="request"></c:set>
修改map
<%
Map map = new HashMap();
map.put("test1", "test1");
map.put("test2", "test2");
map.put("test3", "test3");
request.setAttribute("map", map);
%>
<c:set target="${map }" property="test1" value="testestsetset" />
c:remove
移除某個內置對象的屬性
屬性 | 作用 |
---|---|
var | 移除的屬性名稱 |
scope | 可選 所在的內置對象名稱page、request、session、application |
移除
<%
Map map = new HashMap();
map.put("test1", "test1");
map.put("test2", "test2");
map.put("test3", "test3");
request.setAttribute("map", map);
%>
<c:set target="${map }" property="test1" value="testestsetset" />
<c:remove var="map"/>
c:catch
用來捕獲異常
屬性 | 作用 |
---|---|
var | 存儲錯誤的信息 |
捕獲異常
<c:catch var="error">
<c:out value="${1/0 }"></c:out>
</c:catch>
c:if
用來判斷el 表達式,如果el 表達式爲true ,則會執行標籤內的內容
屬性 | 作用 |
---|---|
var | 存儲el 表達式的結果 |
test | el 表達式,結果必須是boolean 值 |
scope | var 屬性存儲的內置對象 |
判斷
<c:if test="${1==3 }" var="flag" scope="request">
<c:out value="1 not equels 3"></c:out>
</c:if>
c:choose, c:when, c:otherwise
類似於switch 邏輯判斷
判斷
<!-- 結果爲 11 -->
<c:choose>
<c:when test="${3==3 }" >11</c:when>
<c:when test="${3==3 }" >22</c:when>
<c:when test="${3==3 }" >33</c:when>
<c:otherwise>
no when
</c:otherwise>
</c:choose>
c:forEach
用來循環一個集合類型的對象
屬性 | 作用 |
---|---|
items | 集合名稱 |
var | 暫存集合元素 |
begin | 可選 循環開始的索引 |
end | 可選 循環結束的索引 |
step | 可選 步長 |
varStatus | 用來獲取集合元素的信息,它有4個屬性,用來獲取集合的index、count、first、last |
循環
<!--結果
1 from index 0
2 from index 1
3 from index 2
4 from index 3
5 from index 4
-->
<%
ArrayList list = new ArrayList();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
request.setAttribute("list", list);
%>
<c:forEach items="${list}" var="value" varStatus="status" >
${value } from index ${status.index } <br/>
</c:forEach>
c:forTokens
分割一個字符串爲一個集合,用來循環
屬性 | 作用 |
---|---|
items | 字符串 |
delims | 分割字符 |
var | 暫存集合元素 |
begin | 可選 循環開始的索引 |
end | 可選 循環結束的索引 |
step | 可選 步長 |
varStatus | 用來獲取集合元素的信息,它有4個屬性,用來獲取集合的index、count、first、last |
字符串分割
<!--結果
111
222
333
444
555
-->
<c:forTokens items="1111-2222-3333-4444-5555" delims="-" var="item">
${item }<br/>
</c:forTokens>