|
|
Choose in JSP Core Tag Library
|
Tutorials

Jsp

|
Topic |
How is "Choose" tag from JSP Core Tag Library used?
|
|
Explanation |
|
The choose tag of the JSP Core Tag Library is used for conditional execution of statements.
Syntax:
<c:choose>
<c:when.....>
...
</c:when>
<c:when.....>
...
</c:when>
<c:otherwise>
...
</c:otherwise>
</c:choose>
In the above syntax if the condition is "true" the statement or code under the "when" tag will be in execution, if nothing is matched the statement under the tag "otherwise" will be in execution.
Example:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>
<c:forEach var="index" items="Monday,Tuesday,Wenesday,
Thursday,Friday">
# ${index}:
<c:choose>
<c:when test="${index == 'Monday'}">
First day of week!</br>
</c:when>
<c:when test="${index == 'Wenesday'}">
Third day of week!</br>
</c:when>
<c:when test="${index =='Friday'}">
Fifth day of week!</br>
</c:when>
<c:otherwise>
Not a chosen day?</br>
</c:otherwise>
</c:choose>
</c:forEach>
Result::
# Monday: First day of week!
# Tuesday: Not a chosen day?
# Wenesday: Third day of week!
# Thursday: Not a chosen day?
# Friday: Fifth day of week!
In the above example a forEach loop is used to iterate five days of a week
and only the chosen days of the week "Monday, Wenesday, Friday" have a message to display other days
which are not listed display the message given under the "otherwise" tag "Not a chosen day?" is displayed.
|
|
A Note |
|
JSP(Java Server Pages) is one of the most used Server Side Programming Language in the world. Simple introduction, basic program codes with examples. Begin coding your own JSP scripts with this online tutorial. Hope you enjoy this tutorial. Do send your feedback or suggestions on this JavaServer Pages tutorial. This is a copyright content.
|
|
|
|