Welcome to Sun Java System Web Server I18N Technology Samples

Overview

The internationalization (I18N) technology samples are collection of servlets and JavaServer Pages (JSP) used to demonstrate the I18N capabilities of Sun Java System Web Server. The samples cover some of the most frequently used features of Java Servlet and Java Server Pages Specification Implementation in Sun Java System Web Server.

Servlet Samples

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.

Internationalizing JSP With Resource Bundles
The simple ResourceJsp.jsp uses two resource bundles (LocalStrings.properties and LocalStrings_ja.properties) and loads the 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. Click here to run this sample. If you want to try with any other resource bundle, for example, zh, copy the LocalStrings_ja.properties file to LocalStrings_zh.properties and add Chinese (unicode data) to the LocalStrings_zh.properties file. Change your browser's language settings to zh.

Using JavaBeans Properties With JSP
The simple UseBeanJsp.jsp uses the usebean property to set and get the values from a JavaBean component. Click here to run this sample. On the screen that displays, enter your name and a greeting in the appropriate language and click Submit. The JSP displays the information that you entered .

Simple Custom Tag
The simple TaglibJsp uses the tag library i18ntaglib to display localized messages from resource bundles to the user. For this sample, we are using the LocalStrings_ja.properties resource bundle, and the language is set to ja. If you want to try using another other resource bundle such as zh, copy the LocalStrings_ja.properties file to LocalStrings_zh.properties and add Chinese (unicode data) to the LocalStrings_zh.properties file. In the TaglibJsp.jsp file, change the line
<i18n:message name="LocalStrings" key="thanks" language="ja" country="JP" /> to
<i18n:message name="LocalStrings" key="thanks" language="zh" country="CN" />.
Once you are done with the changes, run ant all from the
src directory and restart your server instance. Change your browser's language setting to zh, and verify that the resource bundle is loaded properly and that the Chinese characters display properly.

Simple Filter
A filter is a component that is invoked by the servlet container when a client requests a resource to which the filter is configured, such as a servlet or URL. In this example, a simple filter called SimpleFilter sets the request's character encoding based on two initialization parameters, usefilter and encoding defined in the web.xml file. The usefilter parameter can be set either to true or false. The encoding parameter can be set to any valid encoding (UTF-8 in this example). 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, this example uses SimpleFilter to serve requests for a specific servlet resource, SimpleFilterServlet. Once you click the above link (Set character encoding using a Filter), an HTML page displays with content type set to UTF-8. Enter some multibyte data into the form and click Submit. The resulting page displays the data that you entered.

If you want to try to use other encoding, for example, GB2312, modify the line in web.xml from UTF-8 to GB2312. And modify the line in servletfilter.html from
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8"> to
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=GB2312">.

Once you are done with the changes, run ant all from the src directory and restart your server instance.



How Servlet Request Decoding Works

Character Encoding of the Request

Priority

SetCharacterEncoding()

1

Hidden field

2

default-charset

3

Default (ISO-8859-1)

4


If the application does not set request encoding using setCharacterEncoding(), the web server looks for the hidden field in the request header. If there is any value specified, the web server uses the hidden value to call the ssetCharacterEncoding() method on servlet request. If the hidden field is not available, the web server looks for the default-charset value if this is mentioned in the parameter-encoding element of sun-web.xml. Web server uses the corresponding encoding to call setCharacterEncoding()on servlet request. If there is no default-charset defined in the sun-web.xml file, then the web server uses ISO-8859-1 as default encoding to read the request parameters.

Troubleshooting

If you use the samples with Japanese characters using Netscape Communicator 4.x browser on Windows NT/2000, you might see square boxes or corrupted symbols instead of Japanese characters. If so, you must install unicode or Japanese font on your system.

Downloading and Installing Bitstream Cyberbit Font

Download bitstream cyberbit font (geottf.zip) from http://www.will-harris.com/fonts/freefonts.htm or any other web site, 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.

Setting Up Netscape Communicator

Start the Netscape browser. Select Menu --> Edit --> Preferences. Click Appearance --> Fonts. For Language for encoding, select Japanese. For variable and fixed width fonts, select Bitstream Cyberbit.

Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.