<C: scegliere>, <c: quando>, <c: altrimenti> tag
<C: scegliere> tag e la funzione switch Java come fare una scelta in un certo numero di opzioni.
istruzione switch ha un caso, ma <C: scegliere> tag ha un corrispondente <c: quando>, istruzione switch con un default, e <c: scegliere> tag <c: altrimenti>.
sintassi
<c:choose> <c:when test="<boolean>"/> ... </c:when> <c:when test="<boolean>"/> ... </c:when> ... ... <c:otherwise> ... </c:otherwise> </c:choose>
proprietà
- <C: scegliere> tag non ha attributi.
- <C: quando> tag ha solo attributo, hanno dato nella seguente tabella.
- <C: altrimenti> tag non ha attributi.
proprietà | descrizione | Se necessario | difetto |
---|---|---|---|
prova | condizione | è | no |
Esempi Demo
<%@ 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>
I risultati sono i seguenti:
你的工资为 : 4000 不错的薪水,还能生活。