views:

72

answers:

1

Hi, I'm writing an application in JSF 2.0 which supports many languages, among them ones with special characters. I use String value = request.getParameter("name") and POST method, the page encoding is set to UTF-8 and the app is deployed on apache tomcat 6 which has the connector set correctly to utf-8 in a server.xml file:

 <Connector URIEncoding="utf-8" connectionTimeout="20000" port="8088" protocol="HTTP/1.1" redirectPort="8443"/>

Yes I get strange results like ä for example in place of expected special characters. What should I check next to get rid of the problem? Thanks for help and suggestions.

--------------Edit-------------------

This is the response header:

Server  Apache-Coyote/1.1
Content-Type    text/html;charset=UTF-8
Content-Length  5160
Date    Sun, 10 Oct 2010 15:32:24 GMT

And the request header:

Host    localhost:8088
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 ( .NET CLR 3.5.30729; .NET4.0E)
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language pl,en-us;q=0.7,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://localhost:8088/Panel/addbuilding.jsp
Cookie  JSESSIONID=DD85C95BDFEA9E51B5E4146F2643295D
Pragma  no-cache
Cache-Control   no-cache

Best Regards, sass.

+2  A: 

The URIEncoding="utf-8" has only effect on GET requests. GET comes with the parameters in the request URL (as you see in browser address bar). POST request parameters are however in the request body, not in the request URL. You want to use request.setCharacterEncoding("UTF-8") here. You can do it in a Filter class which is mapped on the FacesServlet.

However, by default JSF should already have taken care about this based on the page encoding (if you're using Facelets). Are you sure that it isn't just the stdout/logging console which is using the wrong encoding to display the parameters?

See also:

BalusC
Thanks a lot, for the answer. I have edited my original post - could you have a look at it? Thanks in advance.
sass
The webbrowser has aborted the request by either pressing `Esc`, navigating away or being closed.
BalusC
Thanks. The encoding is still wrong but I also noticed that it works correctly one or two times directly after the restart of a server. Have you ever observed such behaviour?
sass
Do you see any difference in request/response headers? The *Net* panel of [Firebug](http://getfirebug.com) is helpful in this.
BalusC
I have edited the post again and added full response and request headers.
sass
So it is the same everytime?
BalusC
Yes, looks like it. I should probably ask a fellow programmer to have a look at the code as I cannot post the whole project here. Thanks a lot for help.
sass