⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jstl6.html

📁 j2eePDF格式的电子书
💻 HTML
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  <head>    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />    <meta http-equiv="Content-Style-Type" content="text/css" />    <title>Internationalization Tags</title>    <link rel="StyleSheet" href="document.css" type="text/css" media="all" />    <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" />    <link rel="Table of Contents" href="J2EETutorialTOC.html" />    <link rel="Previous" href="JSTL5.html" />    <link rel="Next" href="JSTL7.html" />    <link rel="Index" href="J2EETutorialIX.html" />  </head>  <body>    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="JSTL5.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="JSTL7.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <blockquote><a name="wp63721"> </a><h2 class="pHeading1">Internationalization Tags</h2><a name="wp64199"> </a><p class="pBody">Chapter <a  href="WebI18N.html#wp83291">17</a> covers how to design Web applications so that they conform to the language and formatting conventions of client locales. This section describes tags that support the internationalization of JSP pages. </p><a name="wp86722"> </a><p class="pBody">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 times in a locale-sensitive or customized manner. <a  href="JSTL6.html#wp86733">Table 14-7</a> lists the tags.</p><div align="left"><table border="1" summary="Internationalization Tags" id="wp86733">  <caption><a name="wp86733"> </a><div class="pTableTitle">Table 14-7   Internationalization Tags&nbsp;</div></caption>  <tr align="center">    <th><a name="wp86741"> </a><div class="pCellHeading">Area</div></th>    <th><a name="wp86743"> </a><div class="pCellHeading">Function</div></th>    <th><a name="wp86745"> </a><div class="pCellHeading">Tags</div></th>    <th><a name="wp86747"> </a><div class="pCellHeading">Prefix</div></th></tr>  <tr align="left">    <td colspan="1" rowspan="3"><a name="wp86749"> </a><div class="pCellBody">I18n</div></td>    <td><a name="wp86751"> </a><div class="pCellBody">Setting Locale</div></td>    <td><a name="wp86753"> </a><div class="pCellBody"><code class="cCode">setLocale</code></div><a name="wp86754"> </a><div class="pCellBody"><code class="cCode">requestEncoding</code></div></td>    <td colspan="1" rowspan="3"><a name="wp86756"> </a><div class="pCellBody"><code class="cCode">fmt</code></div></td></tr>  <tr align="left">    <td><a name="wp86760"> </a><div class="pCellBody">Messaging</div></td>    <td><a name="wp86762"> </a><div class="pCellBody"><code class="cCode">bundle</code></div><a name="wp86763"> </a><div class="pCellBody"><code class="cCode">message</code></div><a name="wp86764"> </a><div class="pCellBody"><code class="cCode">&nbsp;&nbsp;param</code></div><a name="wp86765"> </a><div class="pCellBody"><code class="cCode">setBundle</code></div></td></tr>  <tr align="left">    <td><a name="wp86771"> </a><div class="pCellBody">Number and Date Formatting</div></td>    <td><a name="wp86773"> </a><div class="pCellBody"><code class="cCode">formatNumber</code></div><a name="wp86774"> </a><div class="pCellBody"><code class="cCode">formatDate</code></div><a name="wp86775"> </a><div class="pCellBody"><code class="cCode">parseDate</code></div><a name="wp86776"> </a><div class="pCellBody"><code class="cCode">parseNumber</code></div><a name="wp86777"> </a><div class="pCellBody"><code class="cCode">setTimeZone</code></div><a name="wp86778"> </a><div class="pCellBody"><code class="cCode">timeZone</code></div></td></tr></table></div><p class="pBody"></p><a name="wp86781"> </a><p class="pBody">JSTL i18n tags use a localization context to localize their data. A <em class="cEmphasis">localization context</em> contains a locale and a resource bundle instance. To specify the localization context, you define the context parameter <code class="cCode">javax.servlet.jsp.jstl.fmt.localizationContext</code>, whose value can be a <code class="cCode">javax.servlet.jsp.jstl.fmt.LocalizationContext</code> or a <code class="cCode">String</code>. A <code class="cCode">String</code> context parameter is interpreted as the name of a resource bundle basename. For the Duke's Bookstore application, the context parameter is the <code class="cCode">String</code> <code class="cCode">messages.BookstoreMessages</code>, which is set with <code class="cCode">deploytool</code> in the Context tab of the WAR inspector. This setting can be overridden in a JSP page by using the JSTL <code class="cCode">fmt:setBundle </code>tag. When a request is received, JSTL automatically sets the locale based on the value retrieved from the request header and chooses the correct resource bundle using the basename specified in the context parameter.</p><a name="wp86782"> </a><h3 class="pHeading2">Setting the Locale</h3><a name="wp86713"> </a><p class="pBody">The <code class="cCode">setLocale</code> tag is used to override the client-specified locale for a page. The <code class="cCode">requestEncoding</code> tag is used to set the request's character encoding, in order to be able to correctly decode request parameter values whose encoding is different from <code class="cCode">ISO-8859-1</code>.</p><a name="wp70047"> </a><h3 class="pHeading2">Messaging Tags</h3><a name="wp70064"> </a><p class="pBody">By default, browser-sensing capabilities for locales are enabled. This means that the client determines (via its browser settings) which locale to use, and allows page authors to cater to the language preferences of their clients.</p><a name="wp67328"> </a><h4 class="pHeading3">bundle Tag</h4><a name="wp70076"> </a><p class="pBody">You use the <code class="cCode">bundle</code> tag to specify a resource bundle for a page.</p><a name="wp85745"> </a><p class="pBody">To define a resource bundle for a Web application you specify the context parameter <code class="cCode">javax.servlet.jsp.jstl.fmt.localizationContext</code> in the Web application deployment descriptor. </p><a name="wp85747"> </a><h4 class="pHeading3">message Tag</h4><a name="wp68057"> </a><p class="pBody">The <code class="cCode">message</code> tag is used to output localized strings. The following tag from <code class="cCode"><a  href="../examples/web/bookstore4/web/bookcatalog.txt" target="_blank">bookcatalog.jsp</a></code></p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;h3&gt;&lt;fmt:message key=&quot;Choose&quot;/&gt;&lt;/h3&gt;<a name="wp69383"> </a></pre></div><a name="wp69837"> </a><p class="pBody">is used to output a string inviting customers to choose a book from the catalog.</p><a name="wp70112"> </a><p class="pBody">The <code class="cCode">param</code> subtag provides a single argument (for parametric replacement) to the compound message or pattern in its parent <code class="cCode">message</code> tag. One <code class="cCode">param</code> tag must be specified for each variable in the compound message or pattern. Parametric replacement takes place in the order of the <code class="cCode">param </code>tags. </p><a name="wp70048"> </a><h3 class="pHeading2">Formatting Tags</h3><a name="wp81309"> </a><p class="pBody">JSTL provides a set of tags for parsing and formatting locale-sensitive numbers and dates.</p><a name="wp64198"> </a><p class="pBody">The <code class="cCode">formatNumber</code> tag is used to output localized numbers. The following tag from <code class="cCode"><a  href="../examples/web/bookstore4/web/bookshowcart.txt" target="_blank">bookshowcart.jsp</a></code></p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;fmt:formatNumber value=&quot;${book.price}&quot; type=&quot;currency&quot;/&gt;<a name="wp69396"> </a></pre></div><a name="wp70078"> </a><p class="pBody">is used to display a localized price for a book. Note that since the price is maintained in the database in dollars, the localization is somewhat simplistic, because the <code class="cCode">formatNumber</code> tag is unaware of exchange rates. The tag formats currencies but does not convert them. </p><a name="wp81305"> </a><p class="pBody">Analogous tags for formatting dates (<code class="cCode">formatDate</code>), and parsing numbers and dates (<code class="cCode">parseNumber</code>, <code class="cCode">parseDate</code>) are also available. The <code class="cCode">timeZone</code> tag establishes the time zone (specified via the <code class="cCode">value</code> attribute) to be used by any nested <code class="cCode">formatDate</code> tags.</p><a name="wp81238"> </a><p class="pBody">In <code class="cCode"><a  href="../examples/web/bookstore4/web/bookreceipt.txt" target="_blank">bookreceipt.jsp</a></code>, a &quot;pretend&quot; ship date is created and then formatted with the <code class="cCode">formatDate</code> tag:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;jsp:useBean id=&quot;now&quot; class=&quot;java.util.Date&quot; /&gt;&lt;jsp:setProperty name=&quot;now&quot; property=&quot;time&quot; &nbsp;&nbsp;value=&quot;${now.time + 432000000}&quot; /&gt;&lt;fmt:message key=&quot;ShipDate&quot;/&gt; &lt;fmt:formatDate value=&quot;${now}&quot; type=&quot;date&quot;&nbsp;&nbsp;dateStyle=&quot;full&quot;/&gt;.<a name="wp81284"> </a></pre></div>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="JSTL5.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="JSTL7.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -