<c:choose>标签
<c:choose>就像在Java switch语句,它可以让你在一些替代方案之间选择。switch语句中有case语句,<c:choose>标签具有<c:when>标签。switch语句中有默认default子句来指定一个默认的行为,类似的方式<c:choose>已<c:otherwise>作为default语句。
属性:
- <c:choose>标签没有任何属性。
- <c:when>标记有一个属性,在下文列出。
- <c:otherwise>标签没有任何属性。
<c:when>标签具有以下属性:
属性 | 描述 | Required | Default |
---|---|---|---|
test | 计算条件 | Yes | None |
例子:
<%@ 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.