vwu98...@lycos.com wrote:
Thanks very much André. Please see the below
----- Original Message -----
From: "André Warnier" <a...@ice-sa.com>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Saturday, January 1, 2011 4:26:28 AM GMT -08:00 US/Canada Pacific
Subject: Re: Encoding Issue on POST
vwu98...@lycos.com wrote:
The followings are what I have done for a project in regarding of encoding.
* <%...@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> on
the first line of JSP files
* <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
That looks fine.
* Set URIEncoding="UTF-8" on your <Connector> in server.xml
That matters for a GET, but plays no role for a POST.
* An encoding filter for utf-8.
Can you expand on that ?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The code can be found on the follow page:
http://www.devdaily.com/java/jwarehouse/spring-framework-2.5.3/src/org/springframework/web/filter/CharacterEncodingFilter.java.shtml
and the configuration in web.xml is the following:
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
While the form GET method works correctly for encoding, the form POST doesn't. I need the following codes to get the right encoding for data coming from a form POST method:
try{
tmp = new String(str.getBytes("ISO-8859-1"), "UTF-8");
}catch(Exception ex){}
How exactly are you obtaining "str" in the above ?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The str is the input string which carries data from the form.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I believe that you do not need that filter, and that it is even
counter-productive.
I believe that the effect of the filter is to result in a double-encoding of the data
coming from the form, which is why you are having those problems.
According to what you already set with
<%...@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> on the first line of
JSP files
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
the POST data from your form should already come to the server as UTF-8.
I do not know how Spring works, but assuming it does something like request.getParameter()
to get the form input values, these values should already be properly read as UTF-8, and
your internal String should receive the correct Unicode values.
I have not looked at the filter code, but normally this type of filter will act on the
"content", or "body" of a request, not on the URL.
So in this case, the filter only runs when the request has a body, which is only in the
case of a POST. For a GET (where the form parameters arrive in the query-string part of
the URL, and there is no body), the filter is not in the picture.
That is why you are seeing this problem with POST, but not with GET.
So, take out the filter and let's see what happens.
(And also take out your added code above, it should not be there and will corrupt the
data, when the data is ok.)
If you want a more detailed explanation, come back here.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org