Latest web development tutorials

<c:if> 標籤

JSP 標準標籤庫 JSP標準標籤庫

<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 標準標籤庫 JSP標準標籤庫