<c:if> 標籤
<c:if>標籤判斷運算式的值,如果運算式的值為 true 則執行其主體內容。
語法格式
<c:if test="<boolean>" var="<string>" scope="<string>"> ... </c:if>
屬性
<c:if>標籤有如下屬性:
| 屬性 | 描述 | 是否必要 | 默認值 |
|---|---|---|---|
| test | 條件 | 是 | 無 |
| var | 用於存儲條件結果的變數 | 否 | 無 |
| scope | var屬性的作用域 | 否 | page |
演示實例
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:if 標籤實例</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>我的工資為: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
運行結果如下:
我的工資為: 4000

JSP 標準標籤庫