JSTL c:choose , c:when and c:otherwise Core Tags

The JSTL <c:choose> Core Tag is used when a number of alternatives are available for a particular condition. It works same as of switch statement in java. The <c:choose> is like switch, <c:when> is like case and <c:otherwise> is like default statement.


    <c:when test="${testCondition1}">
       //block of statements
    <c:when test="${testCondition2}">
        //block of statements
      //Other <c:when>
        //block of statements

c:when tag attributes:

Attribute Description Required
test It specify the condition to evaluate. No

  Note: c:choose and c:otherwise tags does not have any attribute.



<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
          c:choose, c:when and c:otherwise JSTL core tag example
		<c:set var="num" value="100"/>
			<c:when test="${num > 10}">
				Number is greater than 10.
				Number is less than or equal to 10.




jsp example 36   Download this example.   Next Topic: JSTL c:import Core Tag with example. Previous Topic: JSTL c:if Core Tag with example.


Please follow and like us:
Content Protection by DMCA.com