<c:if> 标签


<c:if>标签判断表达式的值,如果表达式的值为真则执行其主体内容。

属性

<c:if>标签有如下属性:

属性 描述 是否必要 默认值
test 条件
var 用于存储条件结果的变量
scope var属性的作用域 page

演示实例

  1. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  2. <html>
  3. <head>
  4. <title>c:if 标签实例</title>
  5. </head>
  6. <body>
  7. <c:set var="salary" scope="session" value="${2000*2}"/>
  8. <c:if test="${salary > 2000}">
  9. <p>My salary is: <c:out value="${salary}"/><p>
  10. </c:if>
  11. </body>
  12. </html>

运行结果如下:
  1. My salary is: 4000