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

📄 webi18n5.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<a name="wp88128"> </a><p class="pBody">If the client hasn't set character encoding and the request data is encoded with a different encoding than the default, the data won't be interpreted correctly. To remedy this situation, you can use the <code class="cCode"><a  href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletRequest.html#setCharacterEncoding(java.lang.String)" target="_blank">ServletRequest.setCharacterEncoding(String enc)</a></code> method to override the character encoding supplied by the container. This method must be called prior to reading request parameters or reading input using <code class="cCode">getReader</code>. To control the request encoding from JSP pages, you can use the JSTL <code class="cCode">fmt:requestEncoding</code> tag. </p><a name="wp87001"> </a><p class="pBody">This method must be called prior to parsing any request parameters or reading any input from the request. Calling this method once data has been read will not affect the encoding.</p><a name="wp86536"> </a><h4 class="pHeading3">Page Encoding</h4><a name="wp86537"> </a><p class="pBody">For JSP pages, the <em class="cEmphasis">page encoding</em> is the character encoding in which the file is encoded. </p><a name="wp88961"> </a><p class="pBody">For JSP pages in standard syntax, the page encoding is determined from the following sources:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp86539"> </a><div class="pSmartList1"><li>The Page Encoding value of a JSP property group (see <a  href="JSPIntro13.html#wp72193">Setting Properties for Groups of JSP Pages</a>) whose URL pattern matches the page.</li></div><a name="wp86540"> </a><div class="pSmartList1"><li>The <code class="cCode">pageEncoding</code> attribute of the <code class="cCode">page</code> directive of the page. It is a translation-time error to name different encodings in the <code class="cCode">pageEncoding</code> attribute of the page directive of a JSP page and in a JSP property group.</li></div><a name="wp86541"> </a><div class="pSmartList1"><li>The <code class="cCode">CHARSET</code> value of the <code class="cCode">contentType</code> attribute of the <code class="cCode">page</code> directive.</li></div></ul></div><a name="wp86542"> </a><p class="pBody">If none of the above is provided, ISO-8859-1 is used as the default page encoding.</p><a name="wp88950"> </a><p class="pBody">For JSP pages in XML syntax (JSP documents), the page encoding is determined as described in section 4.3.3 and appendix F.1 of the XMLspecification.</p><a name="wp86544"> </a><p class="pBody">The <code class="cCode">pageEncoding</code> and <code class="cCode">contentType</code> attributes determine the page character encoding of only the file that physically contains the <code class="cCode">page</code> directive. A Web container raises a translation-time error if an unsupported page encoding is specified.</p><a name="wp86548"> </a><h4 class="pHeading3">Response Encoding</h4><a name="wp86549"> </a><p class="pBody">The <em class="cEmphasis">response encoding</em> is the character encoding of the textual response generated from a Web component. The response encoding must be set appropriately so that the characters are rendered correctly for a given locale. A Web container sets an initial response encoding for a JSP page from the following sources:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp86552"> </a><div class="pSmartList1"><li>The <code class="cCode">CHARSET</code> value of the <code class="cCode">contentType</code> attribute of the <code class="cCode">page</code> directive.</li></div><a name="wp86554"> </a><div class="pSmartList1"><li>The encoding specified by the <code class="cCode">pageEncoding</code> attribute of the <code class="cCode">page</code> directive</li></div><a name="wp86921"> </a><div class="pSmartList1"><li>The Page Encoding value of a JSP property group whose URL pattern matches the page. </li></div></ul></div><a name="wp88232"> </a><p class="pBody">If none of the above is provided, ISO-8859-1 is used as the default response encoding.</p><a name="wp88234"> </a><p class="pBody">The <code class="cCode"><a  href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.html#setCharacterEncoding(java.lang.String)" target="_blank">setCharacterEncoding</a></code>, <code class="cCode"><a  href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.html#setContentType(java.lang.String)" target="_blank">setContentType</a></code>, and <code class="cCode"><a  href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.html#setLocale(java.util.Locale)" target="_blank">setLocale</a></code> methods can be called repeatedly to change the character encoding. Calls made after the servlet response's <code class="cCode">getWriter</code> method has been called or after the response is committed have no effect on the character encoding. Data is sent to the response stream on buffer flushes for buffered pages, or on encountering the first content on unbuffered pages. </p><a name="wp88492"> </a><p class="pBody">Calls to <code class="cCode">setContentType</code> set the character encoding only if the given content type string provides a value for the charset attribute. Calls to <code class="cCode">setLocale</code> set the character encoding only if neither <code class="cCode">setCharacterEncoding</code> nor <code class="cCode">setContentType</code> has set the character encoding before. To control the response encoding from JSP pages, you can use the JSTL <code class="cCode">fmt.setLocale</code> tag.</p><a name="wp89023"> </a><p class="pBody">To obtain the character encoding for a locale, the <code class="cCode">setLocale</code> method checks the locale encoding mapping for the Web application. For example, to map Japanese to the Japanese specific encoding <code class="cCode">Shift_JIS</code>, add the following element to the Web application deployment descriptor:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;locale-encoding-mapping-list&gt;&nbsp;&nbsp;&lt;locale-encoding-mapping&gt;&nbsp;&nbsp;&lt;locale&gt;ja&lt;/locale&gt;&nbsp;&nbsp;&lt;encoding&gt;Shift_JIS&lt;/encoding&gt;&nbsp;&nbsp;&lt;/locale-encoding-mapping&gt;&lt;/locale-encoding-mapping-list&gt;<a name="wp89024"> </a></pre></div><a name="wp88451"> </a><p class="pBody">If a mapping is not set for the Web application, <code class="cCode">setLocale</code> uses a J2EE 1.4 Application Server mapping.</p><a name="wp87807"> </a><p class="pBody">The first application in Chapter&nbsp;<a  href="JSPIntro.html#wp65706">12</a> allows a user to choose an English string representation of a locale from all the locales available to the Java 2 platform and then outputs a date localized for that locale. To ensure that the characters in the date can be rendered correctly for a wide variety of character sets, the JSP page that generates the date sets the response encoding to UTF-8 with the following directive:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;%@ page contentType=&quot;text/html; charset=UTF-8&quot; %&gt;<a name="wp87812"> </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="WebI18N4.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="WebI18N6.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 + -