users@glassfish.java.net

Re: Can't set charset to UTF-8

From: <Jan.Luehe_at_Sun.COM>
Date: Wed, 07 Nov 2007 19:14:24 -0800

Gerald,

Gerald Holl wrote:

> Hello,
>
> I'm having troubles setting the charset to UTF-8 on Glassfish:
> [#|2007-11-07T14:38:01.059+0100|WARNING|sun-appserver9.1|org.apache.coyote.tomcat5.CoyoteRequest|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8080-1;_RequestID=aa139129-bed8-45a9-adb5-d099637fcdf8;|PWC4011:
> Unable to set request character encoding to ISO-8859-1 from context
> /myapp, because request parameters have already been read, or
> ServletRequest.getReader() has already been called|#]
>
> I'm confused why the server complains about the ISO-8859-1 character
> encoding.


The container does not complain about the encoding itself, only about
the fact
that you are trying to set the encoding too late, when it is impossible
for the container
to honor it.

See the javadocs of ServletRequest.setCharacterEncoding():

  This method must be called prior to reading request parameters
  or reading input using getReader(). Otherwise, it has no effect.

The container issues a warning to let you know that your call to
ServletRequest.setCharacterEncoding() has no effect, because one of
the above conditions is met.

You should move your call to ServletRequest.setCharacterEncoding()
before you acquire an input reader from the request, and before
you read any request parameters.

Thanks,


Jan

>
> In Firefox, the character encoding is set to ISO-8859-1 instead of
> UTF-8 (Menu View, Character Encoding).
>
> I tried to set a hint in sun-web.xml:
> <locale-charset-info>
> <parameter-encoding default-charset="UTF-8" form-hint-field="UTF-8" />
> </locale-charset-info>
>
> The warnings are still in the server.log
>
> How do I set the charset to UTF-8?
>
>
> cheers,
> Gerald
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>