| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> |
| <HTML> |
| <HEAD> |
| <!-- |
| |
| Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. |
| |
| This program and the accompanying materials are made available under the |
| terms of the Eclipse Public License v. 2.0, which is available at |
| http://www.eclipse.org/legal/epl-2.0. |
| |
| This Source Code may also be made available under the following Secondary |
| Licenses when the conditions for such availability set forth in the |
| Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| version 2 with the GNU Classpath Exception, which is available at |
| https://www.gnu.org/software/classpath/license.html. |
| |
| SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| |
| --> |
| |
| <TITLE>Application Server i18n technology samples</TITLE> |
| |
| <META NAME="GENERATOR" CONTENT="StarOffice 6.0 (Win32)"> |
| |
| <META NAME="CHANGEDBY" CONTENT="Chand Basha"> |
| |
| </HEAD> |
| |
| <BODY LANG=""> |
| |
| <P><FONT FACE="Times New Roman"><FONT SIZE=6><SPAN LANG="en-US"><B>Welcome |
| |
| to the Application Server i18n technology samples</B></SPAN></FONT></FONT></P> |
| |
| <P><FONT FACE="Thorndale, serif"><FONT SIZE=4 STYLE="font-size: 16pt"><SPAN LANG="en-US"><B>Overview</B></SPAN></FONT></FONT></P> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US"><FONT FACE="Thorndale, serif">The |
| |
| i18n technology samples are collection of servlets and jsps used to |
| |
| demonstrate the i18n capabilities of the Application Server. The |
| |
| samples cover some of the most frequently used features of Java |
| |
| Servlet and Java Server Pages Specification Implementation in the |
| |
| Application Server.<BR><BR></FONT><A HREF="/i18n-simple/servlets.html"><FONT FACE="Thorndale, serif">Servlet |
| |
| Samples</FONT></A></SPAN></FONT></P> |
| |
| <P><FONT FACE="Thorndale, serif"><FONT SIZE=3><SPAN LANG="en-US">The |
| |
| servlet samples are collection of simple servlets that provide |
| |
| details such as Formatting dates, including a servlet, forwarding |
| |
| request to another servlet, sending localized error messages, setting |
| |
| character encoding to interpret the request, internationalizing |
| |
| servlets using resource bundles and forwarding request to another |
| |
| resource such as jsp.</SPAN></FONT></FONT></P> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US"><FONT FACE="Thorndale, serif"><A HREF="/i18n-simple/ResourceJsp.jsp">Internationalizing |
| |
| JSP with Resource Bundle</A><BR>The simple ResourceJsp.jsp uses two |
| |
| resource bundles (LocalStrings.properties and |
| |
| LocalStrings_ja.properties) and loads appropriate bundle based on the |
| |
| browser's language settings. To verify that the |
| |
| LocalStrings_ja.properties file is loading properly, change your |
| |
| browser's language settings to "ja". <A HREF="/i18n-simple/ResourceJsp.jsp">Click |
| |
| here</A> to run this sample. If you want to try with any other |
| |
| resource bundle say "zh", copy LocalStrings_ja.properties |
| |
| file to LocalStrings_zh.properties and add chinese (unicode data) to |
| |
| LocalStrings_zh.properties file. Change your browser's language |
| |
| settings to "zh".</FONT></SPAN></FONT></P> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US"><FONT FACE="Thorndale, serif"><A HREF="/i18n-simple/usejsp.html">Using |
| |
| Java Bean with jsp</A><BR>The simple UseBeanJsp.jsp uses the usebean |
| |
| property to set and get the values from a Java Bean. <A HREF="/i18n-simple/usejsp.html">Click |
| |
| here</A> to run this sample. On the screen displayed, enter your name |
| |
| and greeting message (in desired language) and click Submit. The jsp |
| |
| displays the entered information.</FONT></SPAN></FONT></P> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US"><FONT FACE="Thorndale, serif"><FONT SIZE=4><A HREF="/i18n-simple/TaglibJsp.jsp"><FONT SIZE=3>Simple |
| |
| Custom Tag</FONT></A><B><BR></B><FONT SIZE=3>The simple TaglibJsp |
| |
| uses a tag library i18ntaglib to display localized messages from |
| |
| resource bundles to the user. For this sample we are using |
| |
| LocalStrings_ja.properties resource bundle and the language is set to |
| |
| "ja". If you want to try with any other resource bundle say |
| |
| "zh", copy LocalStrings_ja.properties file to |
| |
| LocalStrings_zh.properties and add chinese (unicode data) to |
| |
| LocalStrings_zh.properties file. In the TaglibJsp.jsp file change the |
| |
| line:<BR><i18n:message name="LocalStrings" key="thanks" |
| |
| language="ja" country="JP" /> to<BR><i18n:message |
| |
| name="LocalStrings" key="thanks" language="zh" |
| |
| country="CN" /><BR>Once you are done with the changes, |
| |
| run "asant all" from the directory "src" and |
| |
| restart your server instance. Change your browser's language setting |
| |
| to "zh" and verify that the resource bundle is loaded |
| |
| properly and the chinese characters displayed properly.<BR><BR></FONT></FONT><A HREF="/i18n-simple/servletfilter.html">Simple |
| |
| Filter</A><BR>A Filter is a component that is invoked by the servlet |
| |
| container when a client requests a resource that the Filter is |
| |
| configured to, such as a Servlet or URL. In this example we use a |
| |
| simple filter called SimpleFilter, that sets the request's character |
| |
| encoding based on two initialization parameters, usefilter and |
| |
| encoding defined in web.xml file. The parameter "usefilter" |
| |
| value can be set either to "true" or "false". The |
| |
| parameter "encoding" can be set to any valid encoding. In |
| |
| this example, we have set it to "UTF-8". Depending on this |
| |
| value, the filter sets the character encoding accordingly. Though the |
| |
| filters can be used for all the requests received by the container, |
| |
| in this example we will use the SimpleFilter to serve requests for a |
| |
| specific servlet resource, SimpleFilterServlet. Once you click on the |
| |
| above link (Set character encoding using a Filter), a html page will |
| |
| be displayed whose content type is set to UTF-8. Enter some multi |
| |
| byte data into the form and click Submit. The resulting page displays |
| |
| the data you have entered. If you want to try with any other |
| |
| encoding, for example GB2312, modify the line in web.xml UTF-8 to |
| |
| GB2312. And modify the line in servletfilter.html<BR><META |
| |
| HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8"> with <BR><META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=GB2312">. |
| |
| Once you are done with the changes, run "asant all" from the directory "src" |
| |
| and restart your server instance.</FONT></SPAN></FONT></P> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US"><FONT FACE="Thorndale, serif"><A HREF="/i18n-simple/localecharset.html">Locale |
| |
| charset mapping</A><BR>The Application Server's web container |
| |
| provides a locale-charset mapping to set the request's character |
| |
| encoding if there is no encoding specified to interpret the request. |
| |
| The mapping definition is available in sun-web.xml file. This simple |
| |
| servlet reads the request parameter using the encoding specified in |
| |
| the locale-charset mapping table.<BR><BR><B>How it works</B></FONT><BR>The |
| |
| locale-charset mapping information provided in sun-web.xml file is |
| |
| used by the application server to set request's character encoding if |
| |
| the application does not call setCharacterEncoding() on request |
| |
| object. Here is the priority list for different approaches used by |
| |
| the application server.<BR></SPAN></FONT><BR><BR> |
| |
| </P> |
| |
| <TABLE WIDTH=442 BORDER=1 CELLPADDING=0 CELLSPACING=3> |
| |
| <COL WIDTH=241> |
| |
| <COL WIDTH=190> |
| |
| <THEAD> |
| |
| <TR VALIGN=TOP> |
| |
| <TH WIDTH=241> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">Character |
| |
| encoding of the request</SPAN></FONT></P> |
| |
| </TH> |
| |
| <TH WIDTH=190> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">Priority</SPAN></FONT></P> |
| |
| </TH> |
| |
| </TR> |
| |
| </THEAD> |
| |
| <TBODY> |
| |
| <TR> |
| |
| <TD WIDTH=241 VALIGN=TOP> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">SetCharacterEncoding()</SPAN></FONT></P> |
| |
| </TD> |
| |
| <TD WIDTH=190 SDVAL="1" SDNUM="1041;"> |
| |
| <P ALIGN=CENTER><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">1</SPAN></FONT></P> |
| |
| </TD> |
| |
| </TR> |
| |
| <TR> |
| |
| <TD WIDTH=241 VALIGN=TOP> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">Hidden field</SPAN></FONT></P> |
| |
| </TD> |
| |
| <TD WIDTH=190 VALIGN=BOTTOM SDVAL="2" SDNUM="1041;"> |
| |
| <P ALIGN=CENTER><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">2</SPAN></FONT></P> |
| |
| </TD> |
| |
| </TR> |
| |
| <TR> |
| |
| <TD WIDTH=241 VALIGN=TOP> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">Locale-charset |
| |
| info</SPAN></FONT></P> |
| |
| </TD> |
| |
| <TD WIDTH=190 VALIGN=BOTTOM SDVAL="3" SDNUM="1041;"> |
| |
| <P ALIGN=CENTER><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">3</SPAN></FONT></P> |
| |
| </TD> |
| |
| </TR> |
| |
| <TR> |
| |
| <TD WIDTH=241 VALIGN=TOP> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">Default |
| |
| (ISO-8859-1)</SPAN></FONT></P> |
| |
| </TD> |
| |
| <TD WIDTH=190 VALIGN=BOTTOM SDVAL="4" SDNUM="1041;"> |
| |
| <P ALIGN=CENTER><FONT FACE="Thorndale, serif"><SPAN LANG="en-US">4</SPAN></FONT></P> |
| |
| </TD> |
| |
| </TR> |
| |
| </TBODY> |
| |
| </TABLE> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US"><BR>If the |
| |
| application does not set request encoding using |
| |
| setCharacterEncoding(), the application server looks for the hidden |
| |
| field in the request header. If there is any value specified, the |
| |
| application server uses the hidden value to call |
| |
| setCharacterEncoding() method on servlet request. If the hidden field |
| |
| is not available, the application server looks at the language header |
| |
| to get the locale of the request. If the request locale matches with |
| |
| the the locale defined in locale-charset mapping table, the |
| |
| application server uses the corresponding encoding to call |
| |
| setCharacterEncoding() on servlet request. If there is no locale |
| |
| available in the request header, the application server uses the |
| |
| encoding associated with the default locale defined in locale-charset |
| |
| mapping table. If there is no default locale defined in |
| |
| locale-charset mapping table of sun-web.xml file, then the |
| |
| application server uses ISO-8859-1 as default encoding to read the |
| |
| request parameters.</SPAN></FONT></P> |
| |
| <P STYLE="margin-bottom: 0cm"><FONT FACE="Thorndale, serif"><SPAN LANG="en-US"><B>Trouble |
| |
| Shooting</B><BR><BR>If you use the samples with japanese characters |
| |
| using Netscape Communicator 4.x browser on Windows NT/2000, you may |
| |
| see the characters as square boxes or corrupted instead of Japanese |
| |
| characters. In this case, you will need to install unicode font or |
| |
| Japanese font on your system.</SPAN></FONT></P> |
| |
| <P><FONT FACE="Thorndale, serif"><SPAN LANG="en-US"><B>Download and |
| |
| install Bitstream Cyberbit font:</B><BR><BR>Download bitstream |
| |
| cyberbit font (geottf.zip) , to a temp directory. Use an utility such as |
| |
| winzip to decompress the zip file. To install the font, double click |
| |
| "my computer" --> "control panel" --> "fonts". |
| |
| Select File -->; Install new font and select the font file from the |
| |
| temp directory to install.<BR><BR><B>Setup for Netscape |
| |
| Communicator</B><BR><BR>Start the browser. Select Menu --> Edit |
| |
| --> Preferences. Click Appearance --> Fonts. Select "Japanese" |
| |
| for "Language for encoding". Select "Bitstream |
| |
| Cyberbit" for variable and fixed width fonts</SPAN></FONT></P> |
| |
| |
| </BODY> |
| |
| </HTML> |
| |