You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Cool Techi <co...@outlook.com> on 2013/03/26 10:07:08 UTC

Encoding Problem

        We are working with multiple languages and Korean being one 
of them, in our application we have set up encoding both at tomcat level
 and also spring filter for encoding, but for some reason when we do a 
request.getParameter in our Struts2 action class we receive only ??.

Tomcat Encoding

<Connector port="8080" protocol="HTTP/1.1" 
           connectionTimeout="20000" maxThreads="150"
           redirectPort="8443" URIEncoding="UTF-8"/>


Spring Filter

<filter>
    <filter-name>encodingFilter</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>


EDIT

So a message which are sent as "안녕하세요 kkk" is received as "????? kkk"

What could I be missing?

Regards,

Ayush 

     		 	   		  

RE: Encoding Problem

Posted by Cool Techi <co...@outlook.com>.
This is unfortunately happening in our production server and not on or local servers, hence debugging has become more difficult.

On local servers everything is working fine, both POST and GET requests.

Regards,
Ayush

> Date: Tue, 26 Mar 2013 14:16:24 +0400
> Subject: Re: Encoding Problem
> From: knst.kolinko@gmail.com
> To: users@tomcat.apache.org
> 
> 2013/3/26 Cool Techi <co...@outlook.com>:
> > 1. What is your <filter-mapping> and in what place in filters chain does you filter stand. (Order matters here. If anything calls getParameter() before you filter, parameter decoding happens and you are busted).
> >
> > It is the first in the list of filters.
> >
> > 2. What kind of request fails, POST or GET or both?
> >
> > POST is the one in question currently, will test GET.
> >
> > 3. Have you read the character encodings page of Tomcat FAQ?
> >
> > Yes
> >
> > Regards,
> > Rohit
> >
> >> Date: Tue, 26 Mar 2013 13:14:19 +0400
> >> Subject: Re: Encoding Problem
> >> From: knst.kolinko@gmail.com
> >> To: users@tomcat.apache.org
> >>
> >> 2013/3/26 Cool Techi <co...@outlook.com>:
> >> >
> >> >         We are working with multiple languages and Korean being one
> >> > of them, in our application we have set up encoding both at tomcat level
> >> >  and also spring filter for encoding, but for some reason when we do a
> >> > request.getParameter in our Struts2 action class we receive only ??.
> >> >
> >> > Tomcat Encoding
> >> >
> >> > <Connector port="8080" protocol="HTTP/1.1"
> >> >            connectionTimeout="20000" maxThreads="150"
> >> >            redirectPort="8443" URIEncoding="UTF-8"/>
> >> >
> >> >
> >> > Spring Filter
> >> >
> >> > <filter>
> >> >     <filter-name>encodingFilter</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>
> >> >
> >> >
> >> > EDIT
> >> >
> >> > So a message which are sent as "안녕하세요 kkk" is received as "????? kkk"
> >> >
> >> > What could I be missing?
> >> >
> >>
> >> 1. What is your <filter-mapping> and in what place in filters chain
> >> does you filter stand. (Order matters here. If anything calls
> >> getParameter() before you filter, parameter decoding happens and you
> >> are busted).
> >>
> >> 2. What kind of request fails, POST or GET or both?
> >>
> >> 3. Have you read the character encodings page of Tomcat FAQ?
> >>
> 
> 1. Do not top-post
> http://tomcat.apache.org/lists.html#tomcat-users
> 
> 2. Is HTML page that submits the form served with UTF-8?
> 
> If not, the browser will use a different charset to send the data.
> 
> 3. You may try debugging the getParameter() call
> http://wiki.apache.org/tomcat/FAQ/Developing#Debugging
> 
> You will see whether parameter decoding occurs, or
> it has already occurred at that point, and what data it processes.
> 
> 
> Best regards,
> Konstantin Kolinko
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

Re: Encoding Problem

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/3/26 Cool Techi <co...@outlook.com>:
> 1. What is your <filter-mapping> and in what place in filters chain does you filter stand. (Order matters here. If anything calls getParameter() before you filter, parameter decoding happens and you are busted).
>
> It is the first in the list of filters.
>
> 2. What kind of request fails, POST or GET or both?
>
> POST is the one in question currently, will test GET.
>
> 3. Have you read the character encodings page of Tomcat FAQ?
>
> Yes
>
> Regards,
> Rohit
>
>> Date: Tue, 26 Mar 2013 13:14:19 +0400
>> Subject: Re: Encoding Problem
>> From: knst.kolinko@gmail.com
>> To: users@tomcat.apache.org
>>
>> 2013/3/26 Cool Techi <co...@outlook.com>:
>> >
>> >         We are working with multiple languages and Korean being one
>> > of them, in our application we have set up encoding both at tomcat level
>> >  and also spring filter for encoding, but for some reason when we do a
>> > request.getParameter in our Struts2 action class we receive only ??.
>> >
>> > Tomcat Encoding
>> >
>> > <Connector port="8080" protocol="HTTP/1.1"
>> >            connectionTimeout="20000" maxThreads="150"
>> >            redirectPort="8443" URIEncoding="UTF-8"/>
>> >
>> >
>> > Spring Filter
>> >
>> > <filter>
>> >     <filter-name>encodingFilter</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>
>> >
>> >
>> > EDIT
>> >
>> > So a message which are sent as "안녕하세요 kkk" is received as "????? kkk"
>> >
>> > What could I be missing?
>> >
>>
>> 1. What is your <filter-mapping> and in what place in filters chain
>> does you filter stand. (Order matters here. If anything calls
>> getParameter() before you filter, parameter decoding happens and you
>> are busted).
>>
>> 2. What kind of request fails, POST or GET or both?
>>
>> 3. Have you read the character encodings page of Tomcat FAQ?
>>

1. Do not top-post
http://tomcat.apache.org/lists.html#tomcat-users

2. Is HTML page that submits the form served with UTF-8?

If not, the browser will use a different charset to send the data.

3. You may try debugging the getParameter() call
http://wiki.apache.org/tomcat/FAQ/Developing#Debugging

You will see whether parameter decoding occurs, or
it has already occurred at that point, and what data it processes.


Best regards,
Konstantin Kolinko

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


RE: Encoding Problem

Posted by Cool Techi <co...@outlook.com>.
1. What is your <filter-mapping> and in what place in filters chain does you filter stand. (Order matters here. If anything calls getParameter() before you filter, parameter decoding happens and you are busted).

It is the first in the list of filters.

2. What kind of request fails, POST or GET or both?

POST is the one in question currently, will test GET.

3. Have you read the character encodings page of Tomcat FAQ?

Yes

Regards,
Rohit

> Date: Tue, 26 Mar 2013 13:14:19 +0400
> Subject: Re: Encoding Problem
> From: knst.kolinko@gmail.com
> To: users@tomcat.apache.org
> 
> 2013/3/26 Cool Techi <co...@outlook.com>:
> >
> >         We are working with multiple languages and Korean being one
> > of them, in our application we have set up encoding both at tomcat level
> >  and also spring filter for encoding, but for some reason when we do a
> > request.getParameter in our Struts2 action class we receive only ??.
> >
> > Tomcat Encoding
> >
> > <Connector port="8080" protocol="HTTP/1.1"
> >            connectionTimeout="20000" maxThreads="150"
> >            redirectPort="8443" URIEncoding="UTF-8"/>
> >
> >
> > Spring Filter
> >
> > <filter>
> >     <filter-name>encodingFilter</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>
> >
> >
> > EDIT
> >
> > So a message which are sent as "안녕하세요 kkk" is received as "????? kkk"
> >
> > What could I be missing?
> >
> 
> 1. What is your <filter-mapping> and in what place in filters chain
> does you filter stand. (Order matters here. If anything calls
> getParameter() before you filter, parameter decoding happens and you
> are busted).
> 
> 2. What kind of request fails, POST or GET or both?
> 
> 3. Have you read the character encodings page of Tomcat FAQ?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

Re: Encoding Problem

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/3/26 Cool Techi <co...@outlook.com>:
>
>         We are working with multiple languages and Korean being one
> of them, in our application we have set up encoding both at tomcat level
>  and also spring filter for encoding, but for some reason when we do a
> request.getParameter in our Struts2 action class we receive only ??.
>
> Tomcat Encoding
>
> <Connector port="8080" protocol="HTTP/1.1"
>            connectionTimeout="20000" maxThreads="150"
>            redirectPort="8443" URIEncoding="UTF-8"/>
>
>
> Spring Filter
>
> <filter>
>     <filter-name>encodingFilter</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>
>
>
> EDIT
>
> So a message which are sent as "안녕하세요 kkk" is received as "????? kkk"
>
> What could I be missing?
>

1. What is your <filter-mapping> and in what place in filters chain
does you filter stand. (Order matters here. If anything calls
getParameter() before you filter, parameter decoding happens and you
are busted).

2. What kind of request fails, POST or GET or both?

3. Have you read the character encodings page of Tomcat FAQ?

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


RE: Encoding Problem

Posted by Cool Techi <co...@outlook.com>.
I know this is odd, but I removed 
URIEncoding="UTF-8" from my tomcat and the characters seem to be going 
fine. Cannot understand how this could happen. Also, I know removing UTF-8 encoding would cause problems in GET request, but still cannot figure out this behavior.

Regards,
Ayush

> Date: Tue, 26 Mar 2013 16:12:12 -0400
> From: chris@christopherschultz.net
> To: users@tomcat.apache.org
> Subject: Re: Encoding Problem
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
> 
> Ayush,
> 
> On 3/26/13 5:07 AM, Cool Techi wrote:
> > <filter> <filter-name>encodingFilter</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>
> 
> I would highly recommend against setting forceEncoding=true... this
> will cause Spring's filter to change a client's Content-Type from the
> correct value to the wrong value. If the client sends a Content-Type
> with encoding, you should respect it.
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
> 
> iQIcBAEBCAAGBQJRUgEcAAoJEBzwKT+lPKRYNTYQAJSqIZ4yCQLB40OKM3Selz6D
> O/Gm4R+08BLOp7d4e5oIT63Nhi6FUZf4y92AN3zIHYfS9mOC1DeO30kbwWHDROlQ
> AjfObPcxhkBlLBPtApJhRVfDitUr71Hbm3y36nH+yhx0Z0Fk/jYPI3Vk+JQd6Qbq
> 04RZ+wKOf35lpUmKQYPXgNKQGvU1wbCylDvuAOcAKPsBIpZWbs7jCjt25hFdspVT
> q6MqGZ1Ru49hT47+Gks9JE7RTYG6b3i7+ZmLWXCTuZcVL1N/yqPvawHGh2kV/5ad
> 07meJaWbGKu5viGDG7Q51iDzp5pYLNmvfb2YRg+UuZ5Qnoe1QWETMmFBKL6eoJ7e
> vRGuCmgRLpz84DFqTDA0uzCc5rJzfs2XXnyte5dRPWWUGH94qzl+kAkk7pf1uraR
> 0ja1dQ+OmNQcAzs0wM3uHOwnUxlZyE7ZW1qxeh8fDRQAffOw3f6AV5Yqxxg3b/So
> ufNeCMsNQ9F3SWmMwT9QsHZfIV/9ocCd+QEyWOaU9Nn+tlXV9twe9pEYT2lxC3c5
> MmYhHU/+0p4b+nD0eoLcBfR4pzJYctLz2/2QBnh+Fv2NCZBiQF1rjAnSCGWz0762
> 1zgPxlENcrDyGmWZ6wQT6FTXDP9XMt9yPEKQRh/AmwAzctxKMXM4q8/B3UN5Afo7
> SJwS2PpGWD1q9HrBYy/C
> =0pV2
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

Re: Encoding Problem

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Ayush,

On 3/26/13 5:07 AM, Cool Techi wrote:
> <filter> <filter-name>encodingFilter</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>

I would highly recommend against setting forceEncoding=true... this
will cause Spring's filter to change a client's Content-Type from the
correct value to the wrong value. If the client sends a Content-Type
with encoding, you should respect it.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJRUgEcAAoJEBzwKT+lPKRYNTYQAJSqIZ4yCQLB40OKM3Selz6D
O/Gm4R+08BLOp7d4e5oIT63Nhi6FUZf4y92AN3zIHYfS9mOC1DeO30kbwWHDROlQ
AjfObPcxhkBlLBPtApJhRVfDitUr71Hbm3y36nH+yhx0Z0Fk/jYPI3Vk+JQd6Qbq
04RZ+wKOf35lpUmKQYPXgNKQGvU1wbCylDvuAOcAKPsBIpZWbs7jCjt25hFdspVT
q6MqGZ1Ru49hT47+Gks9JE7RTYG6b3i7+ZmLWXCTuZcVL1N/yqPvawHGh2kV/5ad
07meJaWbGKu5viGDG7Q51iDzp5pYLNmvfb2YRg+UuZ5Qnoe1QWETMmFBKL6eoJ7e
vRGuCmgRLpz84DFqTDA0uzCc5rJzfs2XXnyte5dRPWWUGH94qzl+kAkk7pf1uraR
0ja1dQ+OmNQcAzs0wM3uHOwnUxlZyE7ZW1qxeh8fDRQAffOw3f6AV5Yqxxg3b/So
ufNeCMsNQ9F3SWmMwT9QsHZfIV/9ocCd+QEyWOaU9Nn+tlXV9twe9pEYT2lxC3c5
MmYhHU/+0p4b+nD0eoLcBfR4pzJYctLz2/2QBnh+Fv2NCZBiQF1rjAnSCGWz0762
1zgPxlENcrDyGmWZ6wQT6FTXDP9XMt9yPEKQRh/AmwAzctxKMXM4q8/B3UN5Afo7
SJwS2PpGWD1q9HrBYy/C
=0pV2
-----END PGP SIGNATURE-----

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