> JSP在线手册 > <c:when>

<c:choose>标签与Java switch语句的功能一样,用于在众多选项中做出选择。switch语句中有case,而<c:choose>标签中对应有<c:when>,switch语句中有default,而<c:choose>标签中有<c:otherwise>。

属性

  • <c:choose>标签没有属性。
  • <c:when>标签只有一个属性,在下表中有给出。
  • <c:otherwise>标签没有属性。
<c:when>标签的属性如下:
属性 描述 是否必要 默认值
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. 
上一篇:
下一篇: