JSTL If Else Example
JSTL If Else Example explains about testing different conditions as per the requirements. It also provides a secondary path (else case) of execution, when an "if" conditions become false.
We have already seen the usage of JSTL If Example
How to use if-else option in JSTL?
There are 2 ways, we can achieve if-else statements using JSTL
1) You can use JSTL C:Choose C:When C:Otherwise Tag
2) You can use JSTL Mod (modulus) operator
You can see the below example, which is demonstrating JSTL If Else Example Using Mod operator
Required Libraries
JSTL If Else Example
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <html> <head> <title>JSTL If Else Example</title> </head> <body> <c:set value="18" var="age" /> <c:out value="${num % 2 eq 0 ? 'even': 'odd'}" /> </body> </html>
Output
even