You use the contentType page directive to specify the character encoding for a JSP. For example, you might place the following line at the top of a page:

<% page contentType="text/html; charset=ISO-8859-9"%>

You specify the content type before you retrieve the Java PrintWriter or JspWriter. The charset tag is parsed to select the content type the first time the PrintWriter or JspWriter on the response is created. As data goes through the PrintWriter or JspWriter, it is converted from Unicode to the encoding specified in the contentType directive. Make sure you use the IANA name for the encoding; this is the standard required by the HTTP specification. (See for a list of encoding names.)

With this technique, there is one encoding for each response, so the encoding applies to the entire page.

Alternatively, you can set the content type through a method call as follows:

<% response.setContentType( "text/html; charset=utf-8" ); %>

All code that comes after the method call uses the specified charset. Any code that comes before the method call uses the previous charset setting.

Embedded pages inherit the charset from their parent page.

loading table of contents...