<c:if>標簽判斷表達式的值,如果表達式的值為 true 則執(zhí)行其主體內容。
<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