Pages

Friday, January 13, 2012

GlassFish Default Encoding ISO-8859-1

GlassFish default encoding returns text encoded as ISO-8859-1. This is based on the Hypertext Transfer Protocol -- HTTP/1.1 RFC 3.7.1 Canonicalization and Text Defaults which requires the default encoding for text to be returned in this manner.

Web application developers often use UTF-8 as the encoding in their applications, but fail to change the server defaults. This applies to anything which uses Servlets (including JSP, and JSF). You can change the defaults in the sun-web.xml, or glassfish-web.xml as shown below by setting the parameter-encoding element. This remove a number of default encoding warnings like this:
WARNING: WEB0500: default-locale attribute of locale-charset-info element is being ignored

WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context /, because request parameters have already been read, or ServletRequest.getReader() has already been called.

2 comments: