73
JSTL Core <c:choose>, <c:when>, <c:otherwise> Tag
The < c:choose > tag is a conditional tag that establish a context for mutually exclusive conditional operations. It works like a Java switch statement in which we choose between a numbers of alternatives.
The <c:when > is subtag of <choose > that will include its body if the condition evaluated be ‘true’.
The < c:otherwise > is also subtag of < choose > it follows <when > tags and runs only if all the prior condition evaluated is ‘false’.
The c:when and c:otherwise works like if-else statement. But it must be placed inside c:choose tag.
JSTL Core <c:choose>, <c:when>, <c:otherwise> Example
Let’s see the simple example of < c:choose >, < c:when > < c:otherwise > tag:
This will produce the following result:
Even/Odd Example using c:when and c:otherwise
Output:
Next TopicJSTL Core <c:forEach> Tag