background image

Calls to setContentType

<< Page Encoding | Part 3. Web Services >>
<< Page Encoding | Part 3. Web Services >>

Calls to setContentType

Calls to setContentType set the character encoding only if the given content type string
provides a value for the charset attribute. Calls to setLocale set the character encoding only if
neither setCharacterEncoding nor setContentType has set the character encoding before. To
control the response encoding from JSP pages, you can use the JSTL fmt.setLocale tag.
To obtain the character encoding for a locale, the setLocale method checks the locale encoding
mapping for the web application. For example, to map Japanese to the Japanese-specific
encoding Shift_JIS, follow these steps:
1. Select the WAR.
2. Click the Advanced Settings button.
3. In the Locale Character Encoding table, Click the Add button.
4. Enter ja in the Extension column.
5. Enter Shift_JIS in the Character Encoding column.
If a mapping is not set for the web application, setLocale uses a Application Server mapping.
The first application in
Chapter 5, "JavaServer Pages Technology"
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 by using the following directive:
<%@ page contentType=
"text/html; charset=UTF-8" %>
Further Information about Internationalizing Web
Applications
For a detailed discussion on internationalizing web applications, see the Java BluePrints for the
Enterprise at
http://java.sun.com/blueprints/enterprise
.
Further Information about Internationalizing Web Applications
Chapter 15 · Internationalizing and Localizing Web Applications
475