- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to apply choose tag in JSP?
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.
- Related Articles
- How to apply if tag in JSP?
- How to apply forEach tag in JSP?
- How to apply forTokens tag in JSP?
- I want to create a custom tag in JSP. How to write a custom tag in JSP?
- How to apply a tag to the azure resource group using PowerShell?
- How can I create custom tag in JSP which can accept attribute from parent jsp page?
- What is the use of tag in JSP?
- What is the use of tag in JSP?
- What is the use of tag in JSP?
- What are the standard attributes that should be passed to a custom tag in a JSP page?
- I am facing problem in using include directive tag in jsp. Please share a working example.
- How to use action in JSP?
- How to use action in JSP?
- How to use action in JSP?
- How to use Action in JSP?

Advertisements