JSTL Core <c:choose>, <c:when>, <c:otherwise> Tag


The <c:choose> works like a Java switch statement in that it lets you choose between a number of alternatives. Where the switch statement has case statements, the <c:choose> tag has <c:when> tags. A a switch statement has default clause to specify a default action and similar way <c:choose> has <c:otherwise> as default clause.


  • The <c:choose> tag does not have any attribute.

  • The <c:when> tag has one attributes which is listed below.

  • The <c:otherwise> tag does not have any attribute.

The <c:when> tag has following attributes:

AttributeDescription RequiredDefault
testCondition to evaluateYesNone


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<title><c:choose> Tag Example</title>
<c:set var="salary" scope="session" value="${2000*2}"/>
<p>Your salary is : <c:out value="${salary}"/></p>
    <c:when test="${salary <= 0}">
       Salary is very low to survive.
    <c:when test="${salary > 1000}">
        Salary is very good.
        No comment sir...

This would produce following result:

Your salary is : 4000
Salary is very good.