English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The '<c:choose>' tag has the same function as the Java switch statement and is used to make a choice among many options.
In the switch statement, there is a case, and the corresponding '<c:when>' is in the '<c:choose>' tag. In the switch statement, there is a default, and in the '<c:choose>' tag, there is a '<c:otherwise>'.
<c:choose> The '<c:when test="<boolean>">' ... </c:when> The '<c:when test="<boolean>">' ... </c:when> ... ... <c:otherwise> ... </c:otherwise> </c:choose>
Eigenschaft | Beschreibung | Notwendig | Standardwert |
---|---|---|---|
test | Bedingung | Ja | Kein |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:choose Tagbeispiel</title> </head> <body> <c:set var="salary" scope="session" value="${2000*2"/> <p>Dein Gehalt beträgt : <c:out value="${salary}"/></p> <c:choose> <c:when test="${salary} <= 0}> Schrecklich. </c:when> <c:when test="${salary}> 1000}> Gute Bezahlung, noch kann man leben. </c:when> <c:otherwise> Nichts. </c:otherwise> </c:choose> </body> </html>
Das Laufzeitergebnis ist wie folgt:
Dein Gehalt beträgt : 4000 Gute Bezahlung, noch kann man leben.