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

<x:choose> , <x:when> , <x:otherwise> 표지

JSP 표준 태그 라이브러리

<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>JSTL x:choose 태그</<title>
</<head>
<body>
<h2>Books Info:</h2>
<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>

실행 결과는 다음과 같습니다:

BOOKS INFO:
Book is written by ZARA

JSP 표준 태그 라이브러리