JSTL - Core <c:if> 標籤



<c:if> 標籤評估一個表示式,並且只有當表示式計算結果為 true 時才顯示其主體內容。

屬性

<c:if> 標籤具有以下屬性:

屬性 描述 必填 預設值
test 要評估的條件
var 儲存條件結果的變數名稱
scope 儲存條件結果的變數的作用域 page

示例

<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>

<html>
   <head>
      <title><c:if> Tag Example</title>
   </head>

   <body>
      <c:set var = "salary" scope = "session" value = "${2000*2}"/>
      <c:if test = "${salary > 2000}">
         <p>My salary is:  <c:out value = "${salary}"/><p>
      </c:if>
   </body>
</html>

以上程式碼將生成以下結果:

My salary is: 4000
jsp_standard_tag_library.htm
廣告