tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tremal Naik" <tremaln...@gmail.com>
Subject UTF-8 charset encoding
Date Fri, 16 Nov 2007 13:14:12 GMT
Hello Tomcat users,
I'm developing an application in Jboss 4.0.2, which uses Tomcat 5.5.9
as web tier.

I'm trying to make Tomcat decoding the request body with the correct
encoding. I have problems with IE and Firefox as well. The html page
has the meta tag:

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

all characters are displayed well in both browsers, the page encoding
appears correctly set to UTF-8. The problems arises when I try to
submit "strange" characters as currency symbols (euro, pound, yen,
...) in a form text box.

Debugging Tomcat source, I see the following in the
org.apache.catalina.connector.Request: the parseParameters() method
tries to get the correct encoding:

        String enc = getCharacterEncoding();

the ContentType.getCharsetFromContentType() tries to infer the correct
character encoding from the request Content-Type header, but since it
is not set it returns null:

 public static String getCharsetFromContentType(String type) {
        if (type == null) {
            return null;
        }
        int semi = type.indexOf(";");
        if (semi == -1) {
            return null;
        }

Here the problem is the content type of the http request coming from
the browser is as follows (as grabbed by an http tracer):

Content-Type: application/x-www-form-urlencoded

Hence, it doesn't contain any ";charset=utf-8" appended, as expected.
The body looks to me correctly encoded in UTF-8 format.

Thus, the parseParameters() parses the parameters with its default
character encoding which is ISO-8859-1:

parameters.setEncoding
                (org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING);

Now, I know this is not a Tomcat problem, but I don't know how to
force the client to sent the correct information to the server. Any
ideas how to solve this?
It was nice also if I could set up Tomcat default encoding to UTF-8,
without recompiling the source (I have some requirements on the
Jboss/Tomcat: I can't use a modified or different version).

By the way, I already tried to update the file
$CATALINA_HOME/conf/server.xml for UTF-8 support by connectors with
the parameter URIEncoding="UTF-8".



Thanks for your help,

-- 
TREMALNAIK

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message