English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
<fmt:bundle> 태그는 <fmt:bundle> 태그 내에서 <fmt:message> 태그에 사용할 수 있는 지정된 자원 집합을 표시합니다. 이는 각 <fmt:message> 태그에 대해 자원 집합을 지정하는 많은 단계를 줄일 수 있게 합니다.
예를 들어, 아래의 두 개의 <fmt:bundle> 블록은 같은 출력을 생성합니다:
<fmt:bundle basename="com.w3codebox.Example"> <fmt:message key="count.one"/> </fmt:bundle> <fmt:bundle basename="com.w3codebox.Example" prefix="count."> <fmt:message key="title"/> </fmt:bundle>
<fmt:bundle baseName="<string>" prefix="<string>"/>
<fmt:bundle> 태그는 다음과 같은 속성을 가집니다:
속성 | 설명 | 필수 여부 | 기본 값 |
---|---|---|---|
기본 이름 | 로드된 자원 집합의 기본 이름을 지정합니다 | 네 | 없음 |
접두사 | <fmt:message> 태그의 key 속성의 접두사를 지정합니다 | 아니요 | 없음 |
자원 집합은 지역에 따른 객체를 포함합니다. 자원 집합은 키밸류对人体을 포함합니다. 프로그램이 지역에 따른 자원을 필요로 할 때, 모든 키밸류对人体를 모든 locale에 공유할 수 있지만, locale에 대해 변환된 값을 지정할 수도 있습니다. 자원 집합은 지정된 locale에 대한 내용을 제공하는 데 도움이 됩니다.
Java 자원 집합 파일은 일련의 키밸류对人体을 포함합니다. 우리가 관심을 가지는 메서드는 java.util.ListResourceBundle 클래스를 상속한 컴파일된 Java 클래스를 생성하는 것에 관련됩니다. 이러한 클래스를 컴파일한 후 웹 애플리케이션의 CLASSPATH에 배치해야 합니다.
기본적인 자원 집합을 정의해 보겠습니다:
package com.w;3codebox; import java.util.ListResourceBundle; public class Example_En extends ListResourceBundle { public Object[][] getContents() { return contents; } static final Object[][] contents = { {"count.one", "One"}, {"count.two", "Two"}, {"count.three", "Three"}, }; }
위 파일을 Example.class로 컴파일한 후, 웹 애플리케이션의 CLASSPATH에서 찾을 수 있는 위치에 두세요. 이제 JSTL을 사용하여 이 세 개의 숫자를 표시할 수 있습니다. 예를 들어:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <html> <head> <title>JSTL fmt:bundle 태그</title> </head> <body> <fmt:bundle basename="com.w3codebox.Example" prefix="count."> <fmt:message key="one"/><br/> <fmt:message key="two"/><br/> <fmt:message key="three"/><br/> </fmt:bundle> </body> </html>
실행 결과는 다음과 같습니다:
One Two Three
prefix 속성을 없애기 위해 변경하세요:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <html> <head> <title>JSTL fmt:bundle 태그</title> </head> <body> <fmt:bundle basename="com.w3codebox.Example"> <fmt:message key="count.one"/><br/> <fmt:message key="count.two"/><br/> <fmt:message key="count.three"/><br/> </fmt:bundle> </body> </html>
실행 결과는 다음과 같습니다:
One Two Three
보여줄 수 있습니다<fmt:setLocale>와<fmt:setBundle>자세한 정보를 얻으려면.