This is an archive of an inactive wiki and cannot be modified.

Specifying the Character Encoding

This technique gives background information to CategoryBpCharacterEncodingUse for various scenarios

Apache

In Apache to set the system default character encoding use the AddDefaultCharset directive.

To specify character encodings at directory level, use the AddCharset directive in the .htaccess file to associate a character encoding with a file extension.

Apache will not automatically convert the page from the encoding it is stored in to the encoding specified with these directives i.e the files must be saved in the correct encoding. How to do this depends on the authoring tool used - in general, after selecting Save As ... an option will be available to select the desired character encoding.

See

Java Servlets

In Java Servlets, the character encoding can be specified by invoking either of the setContentType or setCharacterEncoding methods of the ServletResponse interface. After specifying the character encoding all output will automatically be converted to the specified character encoding.

JSP

In JSP use the contentType attribute of the page directive to specify the character encoding of the response. Use the pageEncoding attribute of the page directive to specify the character encoding that the JSP is saved in.

HTML

Inside HTML it is also possible to specify the character encoding as follows:

<meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8">

NB If the character encoding was already specified in the HTTP header then this declaration will generally be ignored.

Back to BestPracticesList


CategoryJava CategoryApache CategoryStatic

Contributions to this wiki are governed by the W3C policies for Contribution to W3C' wiki on Mobile Web.