Internationalization and localization tools


Locale-Sensitive Java Method

javax.servlet.ServletResponse

public void setCharacterEncoding(String charset)

Internationalization (I18n) Method Overview

The method setCharacterEncoding sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.
Note that the charset argument must be one of those defined within the IANA Character Sets. If the character encoding has already been set by setContentType(java.lang.String) or setLocale(java.util.Locale), this method overrides it.

This method can be called repeatedly to change the character encoding. This method has no effect if it is called after ServletResponse.getWriter has been called or after the response has been committed. Containers must communicate the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the character encoding is communicated as part of the Content-Type header for text media types.

I18n Issues

If the charset parameter passed in does not support the characters that the application is attempting to display in the browser, those characters will be corrupted in the resulting page. In order to support multiple languages in a Web application, the UTF-8 Unicode encoding should be used.

Globalyzer will detect this call and report it as an I18n issue regardless of whether it is being used correctly. If an encoding argument is already being passed in, Globalyzer will detect the call anyway to force developers to double check that the correct value is being passed. If you have determined that the call is being handled correctly, you can use Globalyzer's Ignore Comment functionality to ensure that it isn't picked up in a subsequent scan.

Suggested Replacement

public void setCharacterEncoding(
   String utf-8)

Instead of:

response.setCharacterEncoding("ISO-8859");

Use:

response.setCharacterEncoding("UTF-8");

Locale-Sensitive Java Methods

 

Lingoport internationalization and localization services and software