<c:if> Tag

JSP 标准标签库JSP Standard Tag Library

The <c:if> tag evaluates the value of an expression. If the value of the expression is true, it executes its body content.

Syntax Format

<c:if test="<boolean>" var="<string>" scope="<string>">
   ...
</c:if>

Attributes

The <c:if> tag has the following attributes:

Attribute Description Required Default Value
test Condition Yes None
var Variable used to store the result of the condition no None
scope Scope of the var attribute no page

Demo Example

<%@ 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>

The output is as follows:
我的工资为: 4000

JSP 标准标签库JSP Standard Tag Library

Other Extensions