To specify the character encoding for a JSP, you use the contentType page directive. 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 have retrieved 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 www.iana.org 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 shown in the following example:

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

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...