Jsp-jstl-core-choose-tag
提供:Dev Guides
JSTL-コア<c:choose>、<c:when>、<c:otherwise>タグ
*<c:choose>* は、いくつかの選択肢から選択できるという点でJavaの *switch* ステートメントのように機能します。 *switch* ステートメントに *case* ステートメントがある場合、 *<c:choose>* タグには *<c:when>* タグがあります。 switchステートメントにデフォルトアクションを指定する *default* 句があるように、 *<c:choose>* には *<c:otherwise>* がデフォルト句としてあります。
属性
<c:choose> タグには属性がありません。
<c:when> タグには、以下にリストする属性が1つあります。
<c:otherwise> タグには属性がありません。
*<c:when>* タグには次の属性があります-
Attribute | Description | Required | Default |
---|---|---|---|
test | Condition to evaluate | 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.