users@glassfish.java.net

Re: How do I change the URI encoding to UTF-8 in Glassfish

From: <glassfish_at_javadesktop.org>
Date: Fri, 14 Mar 2008 18:28:28 PST

At the beginning of your servlet's processRequest() method, add this line:

  request.setCharacterEncoding("UTF-8");

This made your example work for me.

Instead of hard-coding the request encoding in your servlet, you may specify it in your webapp's sun-web.xml, as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 Servlet 2.4//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-web-app_2_4-0.dtd">

<sun-web-app>
  <locale-charset-info default-locale="">
    <locale-charset-map locale="" charset=""/>
    <parameter-encoding default-charset="UTF-8"/>
  </locale-charset-info>
</sun-web-app>

I think technically, a listener's uriEncoding property applies only to the URI portion of the request, *without* the query string. The query string's encoding needs to be set separately. (There was a long and heated debate about this on tomcat-dev several years ago.)

Please try either of my suggestions and let me know if they work for you.

BTW, in GlassFish, a listener's uriEncoding already defaults to UTF-8, so there is no need to specify this property in domain.xml if you want to use UTF-8.

Thanks,

Jan
[Message sent by forum member 'jluehe' (jluehe)]

http://forums.java.net/jive/thread.jspa?messageID=264155