users@glassfish.java.net

Re: Change encoding for HTML files

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Wed, 10 Feb 2010 12:03:10 -0800

On 02/ 9/10 03:55 PM, glassfish_at_javadesktop.org wrote:
> Hi all, I have a Glassfish server. I handle my servlet encoding through an adequate filter on my web.xml and everything works ok with UTF-8 being my preference.
> However through my web path I want to serve some raw html files. There comes the problem. The files are full UTF-8 (header encoding specified correctly, file text is UTF-8, evrything is OK). But Glassfish serves them as ISO-8859-1 for some reason and some special UTF-8 characters are ruined.
>
> Any ideas?
>
I assume your HTML files specify a Content-Type meta declaration as follows:

  <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />

Note that the web container (in particular, its DefaultServlet) does
not process this declaration, which means you have to "tell" the web
container to set the HTTP Content-Type response header to the above
value. If you wanted to do this portably, you could call
ServletResponse#setCharacterEncoding from your filter (after
configuring your filter such that it would intercept any requests for
your static resources).

Another, non-portable way would be to instruct the DefaultServlet to
do this for you. This container-provided servlet already provides a
fileEncoding init parameter, which may be used to specify the encoding
to be used for reading static resources from the filesystem before serving
them, but it does not include this value in the response encoding, which is
different from what one would expect. There has been some discussion on
whether it should, see

  http://old.nabble.com/DefaultServlet-doesn't-set-charset-td18893115.html

In any case, I would use the filter approach, in order to remain portable.

Thanks,

Jan

> Thanks
> [Message sent by forum member 'greek_manager' (greek_manager_at_hotmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=385771
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>