<c:if>
《c:if》标记仅在表达式求值为true时计算表达式并显示其正文内容。
属性 (Attribute)
《c:if》标记具有以下属性 -
属性 | 描述 | 需要 | 默认 |
---|---|---|---|
test | 要评估的条件 | Yes | None |
var | 用于存储条件结果的变量的名称 | No | None |
scope | 用于存储条件结果的变量的范围 | No | page |
例子 (Example)
<%@ 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