Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to change charset from ISO-8859-1 to UTF-8 in glassfish 3.1

I am having problems to change the charset in my web application response from ISO-8859-1 (default) to UTF-8. I already added the VM option -Dfile.encoding=UTF-8 to the JVM options

But still, I do get the following HTTP Header as a response from the glassfish:

Content-Type: [...;charset=ISO-8859-1]
Server: [GlassFish Server Open Source Edition 3.1]

I would appreciate your help/ideas.

like image 588
Wintermute Avatar asked Jun 08 '11 13:06

Wintermute


2 Answers

The -Dfile.encoding is a Oracle JVM specific setting as to how to read Java source files. This doesn't have any influence on the charset as specified in the Content-Type header of the HTTP response.

You need to add the following to your web.xml in order to send the response of all JSPs as UTF-8 and to let it set the appropriate charset in the response header.

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

See also:

  • Unicode - How to get the characters right?
like image 137
BalusC Avatar answered Oct 08 '22 19:10

BalusC


For UTF-8 fonts on Glassfish3 (Log files, etc):

Go to Server-config > JVM Settings > JVM Options > Add option (-Dfile.encoding=UTF8).

If you are not on -server mode then go to default-config > JVM Settings > JVM Options

like image 20
dimitrios Avatar answered Oct 08 '22 18:10

dimitrios