Latest web development tutorials

<X : 선택>, <X>, <X : 그렇지 않으면> 태그

JSP 표준 태그 라이브러리 JSP 표준 태그 라이브러리

<X : 선택> 태그와 자바의 switch 문은 동일한 기능을 가지고있다. 태그 : 태그는 <시 X>를 가지고 : <선택 X> 스위치 문은 case 문이 있고,. <: 그렇지 않으면 X> 태그 태그가 있습니다 <선택 X> 스위치 문은 기본 문이합니다.

구문

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

재산

  • <X : 선택> 속성이 없습니다.
  • <X : 때> 아래 표에 속성.
  • <X : 그렇지 않으면> 속성이 없습니다.

<X : 때> 태그 속성 :

재산 기술 필요한 경우 디폴트 값
선택 조건 그것은 인 아니

예를 들면 데모

<%@ 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>
<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>

결과는 다음과 같습니다 :

BOOKS INFO:
Book is written by ZARA

JSP 표준 태그 라이브러리 JSP 표준 태그 라이브러리