<C: choisissez>, <c: quand>, <c: autrement> tag
<C: choisissez> et la fonction Java instruction switch pour faire un choix dans un certain nombre d'options.
instruction switch a un cas, mais <c: choose> tag a un <c: quand> correspondant, instruction switch avec un défaut, et <c: choisissez> dans <c: autrement>.
syntaxe
<c:choose> <c:when test="<boolean>"/> ... </c:when> <c:when test="<boolean>"/> ... </c:when> ... ... <c:otherwise> ... </c:otherwise> </c:choose>
propriété
- <C: choose> tag n'a pas d'attributs.
- <C: quand> balise a un seul attribut, ont donné dans le tableau suivant.
- <C: autrement> balise n'a pas d'attributs.
propriété | description | le cas échéant | Par défaut |
---|---|---|---|
test | condition | il est | aucun |
Exemples Démo
<%@ 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 标签实例</title> </head> <body> <c:set var="salary" scope="session" value="${2000*2}"/> <p>你的工资为 : <c:out value="${salary}"/></p> <c:choose> <c:when test="${salary <= 0}"> 太惨了。 </c:when> <c:when test="${salary > 1000}"> 不错的薪水,还能生活。 </c:when> <c:otherwise> 什么都没有。 </c:otherwise> </c:choose> </body> </html>
Les résultats sont les suivants:
你的工资为 : 4000 不错的薪水,还能生活。