jstl的c 標籤用法

來源:互聯網
上載者:User

 

轉自:http://www.web-tag.net/all_8.htmcatch 

<c:catch>動作用於捕獲JSP元素在其體中拋出的異常。

示範代碼:

<c:catch var="err">

         ${param.sampleSingleValue[9] == 3}

</c:catch> 

${err}

更多 catch 資訊

 choose 

用於控制嵌套<c:when>和<c:otherwise>動作的處理。

示範代碼:

<c:choose> 

<c:when test="${product.onSale}"> ...</c:when> 

<c:otherwise> ....</c:otherwise> 

</c:choose> 

更多 choose 資訊

 forEach 

<c:forEach>動作將其體反覆計算固定次數,或者針對一個集合中的每個元素分別計算一次體。

示範代碼:

<c:forEach  items="${map}"  var="mymap"  >
    <c:out  value="${mymap.key}"  />
    <c:out  value="${mymap.value}"  />

</c:forEach> 

更多 forEach 資訊

 forTokens 

標籤可以根據某個分隔字元分隔指定字串,相當於 java.util.StringTokenizer類。

示範代碼:

<c:forTokens items="${userPhone}" delims="-" var="item">
${item}
</c:forTokens>

更多 forTokens 資訊

 if 

<c:if>動作僅當所指定的運算式計算為true時才計算其體。

示範代碼:

<c:if test="${empty param.empDate}"> 

.....

</c:if>

更多 if 資訊

 import 

標籤允許包含另一個JSP頁面到本頁面來。

示範代碼:

<c:import url="/MyHtml.html" var="thisPage" />

 

更多 import 資訊

 otherwise 它等價於“else”語句。
示範代碼:

<c:choose>

    <c:when test="${paramValues.sampleValue[2] == 11}">
        not 12 not 13,it is 11
    </c:when>
    <c:otherwise>not 11 、12、13</c:otherwise>

</c:choose>

更多 otherwise 資訊

 out <c:out>標籤是一個最常用的標籤,用於在 JSP 中顯示資料。它的作用是用來替代通過JSP內 置對象out或者<%=%>標籤來輸出對象的值。
示範代碼:
<c:out value="${sessionScope.username}"/> 

更多 out 資訊

 param 

用於傳遞參數,用來為包含或重新導向的頁面傳遞參數。
示範代碼:

<c:redirect url="/MyHtml.jsp">

<c:param name="userName" value=”RW” />

</c:redirect>

更多 param 資訊

 redirect 

可以將用戶端的請求從一個 JSP 網頁導向到其他檔案。
示範代碼:

<c:redirect url="http://java.sun.com"> 
  
<c:param name="param" value="value"/> 
</c:redirect> 

更多 redirect 資訊

 remove 

<c:remove>標籤用於刪除存在於scope中的變數。類似於<%session.removeAttribute(“name”)%> 、
<%request.removeAttribute(“name”)%>...
示範代碼:

<c:remove var="username" scope="session"/>

更多 remove 資訊

 set 

<c:set>標
簽用於為變數或JavaBean中的變數屬性賦值的工作。這個標籤用於在某個範圍(page、request、session、application
等)中使用某個名字設定特定的值,或者設定某個已經存在的javabean對象的屬性。他類似
於<%request.setAttrbute("name","value");%>

示範代碼:

<c:set value="this is andy" var="oneString"/>

更多 set 資訊

 url 

主要用來產生一個URL。
示範代碼:

<c:url value="http://www.javafan.net " >

<c:param name="param" value="value"/> 

</c:url> 

 

更多 url 資訊

 when 

<c:when>標籤等價於“if”語句,它包含一個test屬性,該屬性工作表示需要判斷的條件。

示範代碼:

<c:when test="${condition1}">

        condition1 為 true

 </c:when>

更多 when 資訊

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.