<c:choose>标签与Java switch语句的功能一样,用于在众多选项中做出选择。switch语句中有case,而<c:choose>标签中对应有<c:when>,switch语句中有default,而<c:choose>标签中有<c:otherwise>。
属性 | 描述 | 是否必要 | 默认值 |
---|---|---|---|
test | 条件 | 是 | 无 |
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:choose 标签实例</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>
运行结果如下:
Your salary is : 4000 Salary is very good.