You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by li...@cit.com.br on 2003/09/06 00:46:34 UTC

Charset encoding issue

Hi, guys. How are you ?

I have a jsp page with some form fields. I don't know how is the right way
to set the charset (because we're using portuguese characters). This is
the only configuration that have worked for me :

<%@ page contentType="html/text; charset=UTF-8"%>

(...)

<form (...) enctype="multipart/form-data">


Is it right ? Is there other way ?



Thanks in advance.



Re[3]: Charset encoding issue

Posted by Francisco Vides Fernandez <pa...@ns3.dedaloingenieros.com>.
I had a similar problem with RH9.0. Form data enconded with
"application/x-www-form-urlencoded" worked just fine with iso8859-1
special characters, but "multipart/form-data" made strange things
appear. 

If I declared the page encoding to be UTF-8, the data was correctly
sent, but the browser was unable to show it properly later. I tested
this with every browser I have access to: Mozilla, Galeon, Firebird,
Konqueror, IE 6.0, and the behavihour was similar in every case.

If I declared the page encoding to be iso8859-1, data was corrupted.

The root of the problem seemed to be in my LOCALE settings. I had
es_ES.UTF-8, and when I changed this to es_ES (without UTF) everything
worked fine again. This is the same in Tomcat 4.0.6 and 4.1.27. I've
found the solution, but I also like to understand better what is
happening here.

Saludos!

-- 
+-----------------
| Francisco Vides Fernández <pa...@dedaloingenieros.com>
| Director técnico.
| Teléfono fijo:   952 60 29 59
| Teléfono móvil:  661 67 32 73
| Fax:             952 60 29 59
| Dédalo Ingenieros http://www.dedaloingenieros.com/
| PGP: http://pgp.rediris.es:11371/pks/lookup?op=index&search=0x5AAE6285
+------


Re: Re [ 4 ] : Charset encoding issue

Posted by Anton Tagunov <at...@mail.cnt.ru>.
Hello Daniel!

Great to know you name at last, have not seen it
in your other posts! :-))

Sorry to have been addressig you by your surname!

DHAL>  How can i spy the traffic between Tomcat and the browsers ?

Just the question I've been waiting for =)
There's view on it in my http://tagunov.tripod.com
page, somewhere down there. Tell if can't find it there.

Anton


Re [ 4 ] : Charset encoding issue

Posted by Daniel H A Lima <li...@cit.com.br>.
Anton Tagunov wrote:

>Hello, Lima!
>
Hi, Anton.

>
>lccb> I've found a message (at
>lccb> http://w6.metronet.com/~wjm/tomcat/2001/Mar/msg00547.html) :
>
>lccb> "Tomcat follows the HTML standard,
>Hmm.., to me it looks like a browser issue, not Tomcat.
>Hence its a bit OT here, but still we have started the
>discussion :-)
>
>(again, as I have suggested before, Lima, you may want
>to spy your browser-tomcat traffic to make sure what bytes
>are transferred exactly, then you'll be sure who is mangling
>the data: Tomcat or browser, my feeling is that this is browser)
>
 How can i spy the traffic between Tomcat and the browsers ?

>
>lccb>  which explicitly declares that MIME type
>lccb> "application/x-www-form-urlencoded" is suitable ONLY for transferring ASCII
>practice seems to be different
>lccb> (but will of course work for ISO 8859-1 as well).
>look, it's already funny: according to the standard
>
>  "application/x-www-form-urlencoded" is suitable ONLY for transferring ASCII
>
>but according to this message the existing software
>
>  will of course work for ISO 8859-1
>  
>did you enjoy this "of course"? ;-)
>lccb>  See
>lccb> http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
>lccb> It says:
>
>lccb> The content type "application/x-www-form-urlencoded" is inefficient
>lccb> for sending large quantities of binary data or text containing non-ASCII
>lccb> characters. The content type "multipart/form-data" should be used for
>lccb> submitting forms that contain files, non-ASCII data, and binary data."
>
>Yup,  but in practice I  beleive that we have succeded many times
>to send cyrillics this way. The browser was running on Windows
>however. All the browsers (huh, do I remember it correctly?)
>were using windows-1251 and koi8-r when the page was encoded with
>the respective encoding).
>
?

>
>lccb> SO           : Red Hat Linux 9
>I assume, both browser and Tomcat, right?
>
    Galeon, Mozilla and Tomcat running in Linux.

>lccb> Browsers     : Galeon e Mozilla
>lccb> Reg. Settings: English
>lccb> Keyboard Set.: English (internacional)
>lccb> Locale       : Not modified. The JVM is using [us,EN], i think. But thats 
>lccb>               ok because i prefer to test my application without change
>lccb> locale to [pt,BR] (we never know when 2 webapp will run using differents
>lccb> locale settings)
>what language are you typing in? what kind of characters get mungled?
>  
>
    Characters from brazilian portuguese. Like 'á', 'ç', 'ã', ...

>lccb> ((3)) I don't know why "page contentType" + "form enctype multipart" is
>lccb> the only working combination but its ok for me. I just would like to
>lccb> understand it :-|
>So do we :-)
>
>  
>
    Thanks !




Re[4]: Charset encoding issue

Posted by Anton Tagunov <at...@mail.cnt.ru>.
Hello, Lima!

lccb> I've found a message (at
lccb> http://w6.metronet.com/~wjm/tomcat/2001/Mar/msg00547.html) :

lccb> "Tomcat follows the HTML standard,
Hmm.., to me it looks like a browser issue, not Tomcat.
Hence its a bit OT here, but still we have started the
discussion :-)

(again, as I have suggested before, Lima, you may want
to spy your browser-tomcat traffic to make sure what bytes
are transferred exactly, then you'll be sure who is mangling
the data: Tomcat or browser, my feeling is that this is browser)

lccb>  which explicitly declares that MIME type
lccb> "application/x-www-form-urlencoded" is suitable ONLY for transferring ASCII
practice seems to be different
lccb> (but will of course work for ISO 8859-1 as well).
look, it's already funny: according to the standard

  "application/x-www-form-urlencoded" is suitable ONLY for transferring ASCII

but according to this message the existing software

  will of course work for ISO 8859-1
  
did you enjoy this "of course"? ;-)
lccb>  See
lccb> http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
lccb> It says:

lccb> The content type "application/x-www-form-urlencoded" is inefficient
lccb> for sending large quantities of binary data or text containing non-ASCII
lccb> characters. The content type "multipart/form-data" should be used for
lccb> submitting forms that contain files, non-ASCII data, and binary data."

Yup,  but in practice I  beleive that we have succeded many times
to send cyrillics this way. The browser was running on Windows
however. All the browsers (huh, do I remember it correctly?)
were using windows-1251 and koi8-r when the page was encoded with
the respective encoding).

lccb> SO           : Red Hat Linux 9
I assume, both browser and Tomcat, right?
lccb> Browsers     : Galeon e Mozilla
lccb> Reg. Settings: English
lccb> Keyboard Set.: English (internacional)
lccb> Locale       : Not modified. The JVM is using [us,EN], i think. But thats 
lccb>               ok because i prefer to test my application without change
lccb> locale to [pt,BR] (we never know when 2 webapp will run using differents
lccb> locale settings)
what language are you typing in? what kind of characters get mungled?

lccb> ((3)) I don't know why "page contentType" + "form enctype multipart" is
lccb> the only working combination but its ok for me. I just would like to
lccb> understand it :-|
So do we :-)


Re[3]: Charset encoding issue

Posted by li...@cit.com.br.
Hi guys. I'll try to answer your questions :

((1))

I've found a message (at
http://w6.metronet.com/~wjm/tomcat/2001/Mar/msg00547.html) that seems to
explain this odd behaviour (but i'm not sure) :

"Tomcat follows the HTML standard, which explicitly declares that MIME type
"application/x-www-form-urlencoded" is suitable ONLY for transferring ASCII
(but will of course work for ISO 8859-1 as well). See
http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
It says:

The content type "application/x-www-form-urlencoded" is inefficient for
sending large quantities of binary data or text containing non-ASCII
characters. The content type "multipart/form-data" should be used for
submitting forms that contain files, non-ASCII data, and binary data."

((2))

>>>>> Fernandez wrote : >>>>>
Fernandez > I've recently have a similar problem with spanish language.
Fernandez > What OS are you running Tomcat on? What are your LOCALE settings?

>>>>> Anton wrote :
Anton > What browser are you using?
Anton > What OS are you on?
Anton > If it is Windows, what are the regional settings?
Anton > Is it an English or a localized version of Windows?
Anton > What language are you typing in?

SO           : Red Hat Linux 9
Browsers     : Galeon e Mozilla
Reg. Settings: English
Keyboard Set.: English (internacional)
Locale       : Not modified. The JVM is using [us,EN], i think. But thats 
              ok because i prefer to test my application without change
locale to [pt,BR] (we never know when 2 webapp will run using differents
locale settings)

((3)) I don't know why "page contentType" + "form enctype multipart" is
the only working combination but its ok for me. I just would like to
understand it :-|


Thanks again, guys !!!

Re[2]: Charset encoding issue

Posted by Anton Tagunov <at...@mail.cnt.ru>.
Hello, Lima!

AT> if you want the form data to be encoded with charset XXX
AT> you need your page to have content type with charset XXX.

LIMA> <form (...) enctype="multipart/form-data">

AT> As far as I know enctype here is not required.

LIMA> But why when i modify or remove the enctype from <form> tag, the browser
LIMA> seems to "forget" the correct charset of these form fields ?

Interesting.. So you are issuing a page

   Content-Type: text/html; charset=UTF-8

it has a form w/o enc-type and the browser does not
encode the non-latin text you type in UTF-8?

What browser are you using?
What OS are you on?
If it is Windows, what are the regional settings?
Is it an English or a localized version of Windows?
What language are you typing in?

For more information could you attach the result of

    wget -s "http://your.site:your-port/your-app/your-page.jsp"

to your mail? (If you're on Windows and do not have wget.exe
already, http://tagunov.tripod.com should have directions on
where to download windows port of wget from).

With wishes of most success in creating localized web
applications, Anton


Re: Charset encoding issue

Posted by li...@cit.com.br.
But why when i modify or remove the enctype from <form> tag, the browser
seems to "forget" the correct charset of these form fields ?

Thanks.

> Hello Lima!
>
> lccb> I have a jsp page with some form fields. I don't know how is the
> right way
> lccb> to set the charset (because we're using portuguese characters). This
> is
> lccb> the only configuration that have worked for me :
>
> lccb> <%@ page contentType="html/text; charset=UTF-8"%>
>
> To the best of my knowledge w3c standards do not prescribe
> the browser what charset to encode form fields with.
> In practice however this is generally the same charset
> that the page containing form is in. So yes, if you want
> the form data to be encoded with charset XXX you need your
> page to have content type with charset XXX. And this is
> what this <%@page%> directive is doing. (In a servlet you
> would do response.setContentType()).
>
> I have written an elaborate essay on this, it should
> still be available at http://tagunov.tripod.com
>
> lccb> <form (...) enctype="multipart/form-data">
> As far as I know enctype here is not required.
>
> lccb> Is it right ? Is there other way ?
> Hope this mail and my old essay have answered at least
> part of your questions.
>
> WBR, Anton
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


Re: Charset encoding issue

Posted by Anton Tagunov <at...@mail.cnt.ru>.
Hello Lima!

lccb> I have a jsp page with some form fields. I don't know how is the right way
lccb> to set the charset (because we're using portuguese characters). This is
lccb> the only configuration that have worked for me :

lccb> <%@ page contentType="html/text; charset=UTF-8"%>

To the best of my knowledge w3c standards do not prescribe
the browser what charset to encode form fields with.
In practice however this is generally the same charset
that the page containing form is in. So yes, if you want
the form data to be encoded with charset XXX you need your
page to have content type with charset XXX. And this is
what this <%@page%> directive is doing. (In a servlet you
would do response.setContentType()).

I have written an elaborate essay on this, it should
still be available at http://tagunov.tripod.com

lccb> <form (...) enctype="multipart/form-data">
As far as I know enctype here is not required.

lccb> Is it right ? Is there other way ?
Hope this mail and my old essay have answered at least
part of your questions.

WBR, Anton


RE: Charset encoding issue

Posted by Francisco Vides Fernandez <pa...@ns3.dedaloingenieros.com>.
I've recently have a similar problem with spanish language. What OS
are you running Tomcat on? What are your LOCALE settings?


>>>>> "lima" == lima  <li...@cit.com.br> writes:

 lima> Hi, guys. How are you ?  I have a jsp page with some form
 lima> fields. I don't know how is the right way to set the charset
 lima> (because we're using portuguese characters). This is the only
 lima> configuration that have worked for me :

 lima> <%@ page contentType="html/text; charset=UTF-8"%>

 lima> (...)

 lima> <form (...) enctype="multipart/form-data">


 lima> Is it right ? Is there other way ?



 lima> Thanks in advance.



 lima> ---------------------------------------------------------------------
 lima> To unsubscribe, e-mail:
 lima> tomcat-user-unsubscribe@jakarta.apache.org For additional
 lima> commands, e-mail: tomcat-user-help@jakarta.apache.org

-- 
+-----------------
| Francisco Vides Fernández <pa...@dedaloingenieros.com>
| Director técnico.
| Teléfono fijo:   952 60 29 59
| Teléfono móvil:  661 67 32 73
| Fax:             952 60 29 59
| Dédalo Ingenieros http://www.dedaloingenieros.com/
| PGP: http://pgp.rediris.es:11371/pks/lookup?op=index&search=0x5AAE6285
+------