Internationalization and localization tools


Locale-Sensitive Java Method

javax.servlet.ServletResponse

public void setContentType(String type)

Internationalization (I18n) Method Overview

The method setContentType sets the content type of the response being sent to the client. The given content type may include a character encoding specification. The response's character encoding is only set via this call if it is called before ServletResponse.getWriter is called. This method may be called repeatedly to change content type and character encoding.

Containers must communicate the content type and 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 Content-Type header is used.

I18n Issues

If the charset parameter passed in as part of the string argument 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 setContentType(
   String contentString)

Instead of:

response.setContentType("text/html;charset=ISO-8859");

Use:

setContentType("text/html;charset=UTF-8");

Locale-Sensitive Java Methods

 

Lingoport internationalization and localization services and software