<c:choose>
《c:choose》工作方式类似于Java switch语句,因为它允许您在多种备选方案之间进行选择。 如果switch语句具有case语句,则《c:choose》标记具有《c:when》标记。 正如switch语句具有指定默认操作的default子句一样, 《c:choose》具有《c:otherwise》作为默认子句。
属性 (Attribute)
《c:choose》标签没有任何属性。
《c:when》标签具有下面列出的一个属性。
《c:otherwise》标签没有任何属性。
《c:when》标记具有以下属性 -
属性 | 描述 | 需要 | 默认 |
---|---|---|---|
test | 要评估的条件 | 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>
上面的代码将生成以下结果 -
Your salary is : 4000
Salary is very good.