Movatterモバイル変換


[0]ホーム

URL:


Document Information

Preface

Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

4.  Java Servlet Technology

5.  JavaServer Pages Technology

6.  JavaServer Pages Documents

7.  JavaServer Pages Standard Tag Library

The Example JSP Pages

Using JSTL

Tag Collaboration

Core Tag Library

Variable Support Tags

Flow Control Tags in the Core Tag Library

Conditional Tags

Iterator Tags

URL Tags

Miscellaneous Tags

XML Tag Library

Core Tags

XML Flow Control Tags

Transformation Tags

Internationalization Tag Library

Setting the Locale

Messaging Tags

ThesetBundle andbundle Tags

Themessage Tag

Formatting Tags

SQL Tag Library

query Tag Result Interface

JSTL Functions

Further Information about JSTL

8.  Custom Tags in JSP Pages

9.  Scripting in JSP Pages

10.  JavaServer Faces Technology

11.  Using JavaServer Faces Technology in JSP Pages

12.  Developing with JavaServer Faces Technology

13.  Creating Custom UI Components

14.  Configuring JavaServer Faces Applications

15.  Internationalizing and Localizing Web Applications

Part III Web Services

16.  Building Web Services with JAX-WS

17.  Binding between XML Schema and Java Classes

18.  Streaming API for XML

19.  SOAP with Attachments API for Java

Part IV Enterprise Beans

20.  Enterprise Beans

21.  Getting Started with Enterprise Beans

22.  Session Bean Examples

23.  A Message-Driven Bean Example

Part V Persistence

24.  Introduction to the Java Persistence API

25.  Persistence in the Web Tier

26.  Persistence in the EJB Tier

27.  The Java Persistence Query Language

Part VI Services

28.  Introduction to Security in the Java EE Platform

29.  Securing Java EE Applications

30.  Securing Web Applications

31.  The Java Message Service API

32.  Java EE Examples Using the JMS API

33.  Transactions

34.  Resource Connections

35.  Connector Architecture

Part VII Case Studies

36.  The Coffee Break Application

37.  The Duke's Bank Application

Part VIII Appendixes

A.  Java Encoding Schemes

B.  About the Authors

Index

 

The Java EE 5 Tutorial

Java Coffee Cup logo
PreviousContentsNext

Internationalization Tag Library

Chapter 15, Internationalizing and Localizing Web Applications covers how to design web applications so that they conform to thelanguage and formatting conventions of client locales. This section describes tags that supportthe internationalization of JSP pages.

JSTL defines tags for setting the locale for a page, creating locale-sensitive messages,and formatting and parsing data elements such as numbers, currencies, dates, and timesin a locale-sensitive or customized manner.Table 7-6 lists the tags.

Table 7-6 Internationalization Tags

Area

Function

Tags

Prefix

I18N

Setting Locale

setLocalerequestEncoding

fmt

Messaging

bundlemessage    paramsetBundle

Number andDate Formatting

formatNumberformatDateparseDateparseNumbersetTimeZonetimeZone

JSTL I18N tags use a localization context to localize their data. Alocalization contextcontains a locale and a resource bundle instance. To specify the localization context atdeployment time, you define the context parameterjavax.servlet.jsp.jstl.fmt.localizationContext, whose value can beajavax.servlet.jsp.jstl.fmt.LocalizationContext or aString. AString context parameter is interpreted as aresource bundle base name. For the Duke’s Bookstore application, the context parameter istheStringmessages.BookstoreMessages. When a request is received, JSTL automatically sets the localebased on the value retrieved from the request header and chooses the correctresource bundle using the base name specified in the context parameter.

Setting the Locale

ThesetLocale tag is used to override the client-specified locale for a page.TherequestEncoding tag is used to set the request’s character encoding, in orderto be able to correctly decode request parameter values whose encoding is differentfromISO-8859-1.

Messaging Tags

By default, the capability to sense the browser locale setting is enabled inJSTL. This means that the client determines (through its browser setting) which localeto use, and allows page authors to cater to the language preferences oftheir clients.

ThesetBundle andbundle Tags

You can set the resource bundle at runtime with the JSTLfmt:setBundle andfmt:bundle tags.fmt:setBundle is used to set the localization context in a variableor configuration variable for a specified scope.fmt:bundle is used to set theresource bundle for a given tag body.

Themessage Tag

Themessage tag is used to output localized strings. The following tagfromtut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookcatalog.jsp is used to output a string inviting customers to choosea book from the catalog.

<h3><fmt:message key="Choose"/></h3>

Theparam subtag provides a single argument (for parametric replacement) to the compoundmessage or pattern in its parentmessage tag. Oneparam tag must be specifiedfor each variable in the compound message or pattern. Parametric replacement takes placein the order of theparam tags.

Formatting Tags

JSTL provides a set of tags for parsing and formatting locale-sensitive numbers anddates.

TheformatNumber tag is used to output localized numbers. The following tag fromtut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookshowcart.jsp is used to display a localized price for a book.

<fmt:formatNumber value="${book.price}" type="currency"/>

Note that because the price is maintained in the database in dollars, thelocalization is somewhat simplistic, because theformatNumber tag is unaware of exchange rates.The tag formats currencies but does not convert them.

Analogous tags for formatting dates (formatDate) and for parsing numbers and dates (parseNumber,parseDate) arealso available. ThetimeZone tag establishes the time zone (specified with thevalueattribute) to be used by any nestedformatDate tags.

Intut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookreceipt.jsp, a “pretend” ship date is created and then formatted with theformatDate tag:

<jsp:useBean /><jsp:setProperty name="now" property="time"     value="${now.time + 432000000}" /><fmt:message key="ShipDate"/> <fmt:formatDate value="${now}" type="date"    dateStyle="full"/>.
PreviousContentsNext

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices


[8]ページ先頭

©2009-2025 Movatter.jp