JSTL Core tag – if() : Function



The <c:if> tag evaluates an expression and displays its body content only if the expression evaluates to true.

Attribute:

The <c:if> tag has following attributes:

Attribute Description Required Default
test Condition to evaluate Yes None
var Name of the variable to store the condition’s result No None
scope Scope of the variable to store the condition’s result No page

JSTL Example :

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>JSTL Tag Example</title>
</head>
<body>

<c:set var="marks" scope="session" value="${32*2}"/>
<c:if test="${marks > 60}">
   <p>My marks is : <c:out value="${marks}"/><p>
</c:if>

</body>
</html>

Output :

My marks is : 64