English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
<c:if> tag evaluates an expression, and if the value of the expression is true, it executes its body content.
<c:if test="<boolean>" var="<string>" scope="<string>"> ... </c:if>
The <c:if> tag has the following attributes:
Attribute | Description | Is it necessary | Default Value |
---|---|---|---|
test | Condition | Yes | None |
var | Used to store the variable for conditional results | No | None |
scope | The scope of var attribute | No | 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 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>
The running result is as follows:
My salary is: 4000