Locale-Sensitive Java Method
javax.servlet.ServletResponse
public void setLocale(Locale locale)
Internationalization (I18n) Method Overview
This method sets the locale of the http response as well as the response's
character encoding if the character encoding has not already been explicitly set
using setContentType(String type)
or
setCharacterEncoding(String encoding) and if
ServletResponse.getWriter hasn't been called yet. If the web application's
deployment descriptor contains a locale-encoding-mapping-list element,
and that element provides a mapping for the given locale, that mapping is used.
Otherwise, the mapping from locale to character encoding is container dependent.
In servlet 2.2 environments, the setLocale method generally maps the specified
locale to a native character encoding that is not Unicode. The following call
response.setLocale(new Locale("ja_JP"));
results in a character set of Shift_JIS, which was a common, pre-Unicode encoding used on
Japanese systems and provides an encoding for all Japanese characters.
I18n Issues
It is recommended I18n practice to use the UTF-8 character encoding for web content in order to ensure
support for all languages. Because setLocale encodes the data using a non-Unicode
encoding unless otherwise specified in the web application's deployment descriptor, it is recommended that developers
replace these calls with a call that explicitly sets the encoding to UTF-8, such as
setCharacterEncoding .
Suggested Replacement
Instead of:
response.setLocale(localeObject);
Use:
response.setCharacterEncoding("UTF_8");
Locale-Sensitive Java Methods
|