
- Basic JSP Tutorial
- JSP - Home
- JSP - Overview
- JSP - Environment Setup
- JSP - Architecture
- JSP - Lifecycle
- JSP - Syntax
- JSP - Directives
- JSP - Actions
- JSP - Implicit Objects
- JSP - Client Request
- JSP - Server Response
- JSP - Http Status Codes
- JSP - Form Processing
- JSP - Writing Filters
- JSP - Cookies Handling
- JSP - Session Tracking
- JSP - File Uploading
- JSP - Handling Date
- JSP - Page Redirect
- JSP - Hits Counter
- JSP - Auto Refresh
- JSP - Sending Email
- Advanced JSP Tutorials
- JSP - Standard Tag Library
- JSP - Database Access
- JSP - XML Data
- JSP - Java Beans
- JSP - Custom Tags
- JSP - Expression Language
- JSP - Exception Handling
- JSP - Debugging
- JSP - Security
- JSP - Internationalization
- JSP Useful Resources
- JSP - Questions and Answers
- JSP - Quick Guide
- JSP - Useful Resources
- JSP - Discussion
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. Just as a switch statement has the default clause to specify a default action, <c:choose> has <c:otherwise> as the default clause.
Attribute
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 the following attributes −
Attribute | Description | Required | Default |
---|---|---|---|
test | Condition to evaluate | Yes | None |
Example
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> <html> <head> <title><c:choose> Tag Example</title> </head> <body> <c:set var = "salary" scope = "session" value = "${2000*2}"/> <p>Your salary is : <c:out value = "${salary}"/></p> <c:choose> <c:when test = "${salary <= 0}"> Salary is very low to survive. </c:when> <c:when test = "${salary > 1000}"> Salary is very good. </c:when> <c:otherwise> No comment sir... </c:otherwise> </c:choose> </body> </html>
The above code will generate the following result −
Your salary is : 4000 Salary is very good.
jsp_standard_tag_library.htm
Advertisements