如何應用 JSP 中的標記?


<c:if> 標籤評估表示式並僅在表示式評估為 true 時顯示其 body 內容。

屬性

<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

更新時間: 30-Jul-2019

219 次觀看

開啟您的事業

完成課程獲取認證

開始
廣告