W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
<x:choose>標(biāo)簽與Java switch語(yǔ)句有相同的功能。switch語(yǔ)句有case語(yǔ)句,而<x:choose>標(biāo)簽有<x:when>標(biāo)簽。switch語(yǔ)句有default語(yǔ)句,而<x:choose>標(biāo)簽有<x:otherwise>標(biāo)簽。
<x:choose> <x:when select="<string>"> ... </x:when> <x:when select="<string>"> ... </x:when> ... ... <x:otherwise> ... </x:otherwise> </x:choose>
<x:when>標(biāo)簽的屬性:
屬性 | 描述 | 是否必要 | 默認(rèn)值 |
---|---|---|---|
select | 條件 | 是 | 無(wú) |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> <html> <head> <title>JSTL x:choose 標(biāo)簽</title> </head> <body> <h3>Books Info:</h3> <c:set var="xmltext"> <books> <book> <name>Padam History</name> <author>ZARA</author> <price>100</price> </book> <book> <name>Great Mistry</name> <author>NUHA</author> <price>2000</price> </book> </books> </c:set> <x:parse xml="${xmltext}" var="output"/> <x:choose> <x:when select="$output//book/author = 'ZARA'"> Book is written by ZARA </x:when> <x:when select="$output//book/author = 'NUHA'"> Book is written by NUHA </x:when> <x:otherwise> Unknown author. </x:otherwise> </x:choose> </body> </html>
運(yùn)行結(jié)果如下:
BOOKS INFO: Book is written by ZARA
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: