JSTL Core c:choose

The <c:choose> works like a Java switch statement it allows to check an expression with various conditions. <c:choose> has <c:when> sub-element to allow you to check an expression. There  can be multiple <c:when> in single <c:choose>.This tag has <c:otherwise> sub-element like default clause in switch case.

Example

index.jsp

  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:choose> Tag Example</title>
</head>
<body>
<c:set var="num" scope="request" value="2"/>
<c:choose>
 <c:when test="${num eq 1}">
Num has value 1
 </c:when>
 <c:when test="${num eq 2}">
Num has value 2
 </c:when>
 <c:otherwise>
No value matched
 </c:otherwise>
</c:choose>
</body>
</html>

Leave a Reply