if-else option in JSTL


if-else option in JSTL

if-else option in JSTL is use to check the condition. It is equivalent to java if-else statement and it returns true when condition will be true other wise false.

Syntax

<c:if test="${condition}">
...
</c:if>

Example

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL Examples</title>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
</head>
<body>
 <c:set var="age" scope="request" value="20" />
 <c:if test="${age >= 18}">
 <c:out value="You are not Child." />
 </c:if>
</body>
</html>

Output

JSTL ExamplesYou are not Child.

 

 






Full-stack web and mobile app development company Contact Us : Skype: indore.webcoder Email: info@w3sparks.com Sales: +91 8085506229