In this Java EE JSP JSTL tutorial, we will see how to use ‘if’ tag and its test and var attributes to make conditional flow in the JSP Page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<!-- Sample 01: Use Core Tags --> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ 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>Insert title here</title> </head> <body> <!-- Sample 02: Set and Get the Variable with JSTL --> <c:set var="Num1" value="10" scope="page"/> <!-- Sample 03: Check for If Condition --> <c:if test="${Num1 > 5 }" > <p> Num1 is more than 5 </p> </c:if> <!-- Sample 04: Store Condition Result for Later usage --> <c:if test="${Num1 > 5 }" var="isHigh" /> <p> Some Html Content Text </p> <c:if test="${isHigh}" > <h1> Yes! High</h1> </c:if> </body> </html> |
Categories: JSP