tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Delbecq <delbd+jaka...@oma.be>
Subject Re: Tomcat 6 UTF-8 GET and POST - please Help..
Date Thu, 10 Jan 2008 19:12:48 GMT
As you might infer, URIEncoding="UTF-8" only work on the Uri part, and 
thus affect only GET. The post is decoded using the browser provided 
"content-encoding". Most borwser don't bother to set that header. 
Behaviour of tomcat is to then use some default (ISO-8859-1). Best way 
to ensure tomcat will use UTF-8 for post decoding is to force it using 
request.setCharacterEncoding("UTF-8"), before any call to 
getParameter(s). a filter or a valve might be a good place :)

btw, be carefull, struts (i see you use struts) tends to also have his 
default behaviour when decoding POST :)



Aleksandar Matijaca a écrit :
> Hi there,
>
> I am having some issue with submitting foreign language fonts in HTML form
> to Tomcat.
> If I set up the FORM with method="GET" everything works just fine.  However,
> when I use
> POST, things don't work -  I get garbled characters in my servlet from the
> FORM.
> In the example below, I am showing the headers for both
> GET and POST - the character being sent is a single lower case letter "f" in
> cyrillic.
>
>
> ************************************************
>
> The POST method does not work - gives garbled characters - please note that
> the mytext is PROPERLY ENCODED IN BOTH methods - GET and POST,
> so I don't think that it is a browser issue (i think that my HTML is ok
> too).
>
>
> http://localhost:8080/Inter/takeText.do
>
> POST /Inter/takeText.do HTTP/1.1
> Host: localhost:8080
> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11)
> Gecko/20071127 Firefox/2.0.0.11
> Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9
> ,text/plain;q=0.8,image/png,*/*;q=0.5
> Accept-Language: en-us,en;q=0.8,sr;q=0.5,hi;q=0.3
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://localhost:8080/Inter/takeText.do
> Cookie: JSESSIONID=yhhvgybm2jfa; sensitivity=1000.0;
> JSESSIONID=AF8D24C63CE9C16D5DF78E5CDDE26146
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 13
> mytext=%D1%84
>
>
> ********************************************************************
>
> This is the request using GET - this works just fine - the servlet gets
> mytext nicely decoded...
>
>
> http://localhost:8080/Inter/takeText.do?mytext=%D1%84
>
> GET /Inter/takeText.do?mytext=%D1%84 HTTP/1.1
> Host: localhost:8080
> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11)
> Gecko/20071127 Firefox/2.0.0.11
> Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9
> ,text/plain;q=0.8,image/png,*/*;q=0.5
> Accept-Language: en-us,en;q=0.8,sr;q=0.5,hi;q=0.3
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://localhost:8080/Inter/takeText.do?mytext=%D1%84
> Cookie: JSESSIONID=yhhvgybm2jfa; sensitivity=1000.0;
> JSESSIONID=AF8D24C63CE9C16D5DF78E5CDDE26146
>
>
>
> ***********************************************
> My HTML (rendered from the JSP)
>
>
> <html>
> <head>
>     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
>
> </head>
> <body>
>             <form name="InputLanguageForm" method="POST"
> action="/Inter/takeText.do" accept-charset="UTF-8" >
>                 <input type="text" name="mytext" value="">
>                 <input type="submit" value="Do it">
>             </form>
> </body>
> </html>
>
> ************************************************
>
> This is the configuration of the Tomcat Connector - if I REMOVE URIEncoding,
> both GET and POST don't work any more.
>
> <Connector port="8080" protocol="HTTP/1.1"
>                connectionTimeout="20000" URIEncoding="UTF-8"
>                redirectPort="8443" />
>
> ************************************************
>
>
> Thanks for any insight you can give me here...  I really don't want to
> change ALL my forms to GET - there should be
> an easier (and more natural) fix for this.
>
> Thanks, Alex.
>
>   


---------------------------------------------------------------------
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