Using Java extensions  Chapter 22: Creating Java Servlets

Chapter 21: Creating Web Applications

Localizing Web applications

EAServer supports the HTTP 1.1 internationalization features defined in the Java Servlet 2.3 specification. Using these features, you can develop servlets that respond in the language specified by the request header, or configure localized versions of Web site’s static pages.

For complete information about HTTP 1.1 internationalization, refer to the Java Servlet 2.3 specification and the HTTP 1.1 specification.

Enabling accept-language header parsing

HTTP 1.1 supports internationalization via an accept-language header that can be included in requests. The accept-language headers describe the languages the client accepts. For example, if documents are stored on the server in Japanese and English, clients that use Japanese as the accept-language header receive the Japanese version of the page. When clients use English as the accept-language header, they receive the English version. Accept-language headers can be sent only by Web browsers that use the HTTP 1.1 protocol.

The property determines whether EAServer parses accept-language headers to respond to requests for localized content. To enable accept-language header parsing, set this property to true using the Advanced tab in the Server Properties window in EAServer Manager.

Internationalization for servlets

For servlet development, EAServer supports internationalization compliant methods that are described in the Java Servlet 2.3 specification. These methods, getLocale and getLocales on the ServletRequest interface and setLocale on the ServletResponse interface:

Deploying localized static files

A separate directory is required for each supported language along with a default directory. EAServer refers to these directories to locate different language versions of a document. For example, if the client requests the URL: 

and EAServer supports English and French. There will be two versions of the page on the server plus the default:

Language selection algorithm

A Language selection algorithm selects the appropriate language after evaluating the override criteria and the quality values specified. If multiple languages are specified, then the algorithm checks the various options in descending order of priority. For example, if the client requests this URL with en, fr specified in the accept-language header:

EAServer first looks for:

If not found, the server looks for:

If this is not found, the server tries to load the default page:

Similarly, for static Web resources in a Web applications, the language name tag is prefixed to the static web resource URL to construct the URL for the resource. EAServer provides multiple language support to the following Web application resources:

Localizing JSP content

JSPs that use a character set other than the server default require additional changes in source code and deployment properties.

In your JSP source code, specify the encoding in the page declaration, for example:

<%@ page contentType="text/html;charset=BIG5" %>

When initializing strings, pass the encoding name to the String constructor, for example:

byte[] b = { (byte)'\u00A4', (byte)'\u00A4',
             (byte)'\u00A4', (byte)'\u00E5' };
String s = new String(b, "big5");

If you do not specify the encoding name, the byte array may be converted incorrectly.

When deploying localized JSPs, group JSPs for each language in their own directory tree under your Web application’s context root. For example, all files under /en are English, 8859_1 encoded and all files under /ko are Korean, KSC5601 encoded. Additionally, configure the following Web application properties:

Property name

Used to specify

Character set for request parameters.

Character set for request body data (retrieved with ServletRequest.getReader or ServletRequest.getInputStream).

Character set for JSP compilation.

The property values must contain a list of URL-pattern and Java character set name pairs. Use this syntax, where URL_pattern is the url-pattern to which the character set applies, and character_set is the name of the Java character set:


For example, for a Web application with two directories, /en and /ko, in its document root where all files under /en are 8859_1 encoded and all files under /ko are KSC5601 encoded, specify the character sets like this:


If a URL pattern is not listed, the server’s default character set is used. If you specify a character set that is not supported, it is not added to the mapping and the server’s default character set is used.

NoteThese character set properties are not supported for the default Web application.

Copyright © 2005. Sybase Inc. All rights reserved. Chapter 22: Creating Java Servlets