Javaserver Pages





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
JSP Tutorial
Introduction Introduction
Installing JDK-Windows Installing JDK-Windows
Installing JDK-Linux Installing JDK-Linux
Installing Tomcat Installing Tomcat
Simple Program in JSP Simple Program in JSP
Pre-defined Variables Pre-defined Variables
Syntax of Tags Syntax of Tags
JSP Expression Language JSP Expression Language
JSP EL Operators JSP EL Operators
EL Implicit Variables EL Implicit Variables
Scopes Scopes
Using Arrays Using Arrays
Methods Methods
JSP Elements JSP Elements
Including Beans Including Beans
JSTL Tags JSTL Tags
Custom Tags Custom Tags
Session Session in JSP
Handling Cookies Handling Cookies
JSP Application Structure JSP Application Structure
Configuring web.xml Configuring web.xml
Tomcat Configuration Tomcat Configuration
JSP Examples JSP Examples
Forums Ask Your Doubts
Feedback Feedback
 




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.


Other Links

web hosting