English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

<x:choose> , <x:when> , <x:otherwise> 标签

JSPStandardTagBibliothek

<x:choose>标签与Java switch语句有相同的功能。switch语句有case语句,而<x:choose>标签有<x:when>标签。switch语句有default语句,而<x:choose>标签有<x:otherwise>标签。

语法格式

<x:choose>
 <x:when select="<string>">
     ...
 </x:when>
 <x:when select="<string>">
     ...
 </x:when>
     ...
     ...
 <x:otherwise>
     ...
 </x:otherwise>
</x:choose>

属性

  • <x:choose>没有属性。

  • <x:when>的属性在下表中给出。

  • <x:otherwise>没有属性。

<x:when>标签的属性:

属性描述是否必要默认值
select 条件

 

示例演示

<%@ 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>JSTLx:chooseTag</title>
</head>
<body>
<h2>BücherInformationen:</h2>
<c:setvar='xmltext'>
  <books>
    <book>
      <name>PadamHistory</name>
      <author>ZARA</author>
      <price>100</price>
    </book>
    <book>
      <name>GreatMistry</name>
      <author>NUHA</author>
      <price>2000</price>
    </book>
  </books>
</c:set>
<x:parsexml='${xmltext}'var='output'/>
<x:choose>
   <x:whenselect="$output//book/author='ZARA'>
      BuchgeschriebenvonZARA
   </x:when>
   <x:whenselect="$output//book/author='NUHA'>
      BuchgeschriebenvonNUHA
   </x:when>
   <x:otherwise>
      UnbekannterAutor.
   </x:otherwise>
</x:choose>
</body>
</html>

LaufenderErgebnis:

BUCHINFORMATIONEN:
BuchgeschriebenvonZARA

JSPStandardTagBibliothek