Monday, 4 February 2013

Tomcat support for UTF-8 encoded parameter


So here is the deal. My JSP file should get a parameter that  contain Russian text , which is encoded in UTF-8

Это тест


Later this parameter is passed into Siebel CRM system which is defined as UTF-8. How it does it and why is not really important . What is important that instead of the Russian text I see ????????????? . Nice ,haa?


I spend about 3 hours searching forums ,tutorials and so on and so on, but none of the proposed solution did the work. However the COMBINATION of proposed solutions did the work.

   Could be that some of the steps are not necessary to achieve the goal. You are most welcome to try to eliminate some of them.

Here a list of configurations that eventually caused my Tomcat to handle the parameter properly

1. I save the JSP page in UTF-8 format. For this I used “Notepad++” (If you don’t know that is “Notepad++” you are probably still leave in 20th century)


2. Put a UTF-8 declaration at the top on the JSP page


3. Set character encoding to UTF-8*


* Some examples proposed to create a filter. See no reason to do it in my case

4. Configure Tomcat’s “Connector” (in server.xml file) to handle requests as UTF-8


5. Define Java JVM paramter “file.encoding” as UTF-8

a. If you start Tomcat from command line (on Windows), use:

   set CATALINA_OPTS=”-Dfile.encoding=UTF-8”

b. If you run Tomcat as a service (on Windows), inside Tomcat’s bin directory execute “tomcat7w.exe” file . and it “Java” tab, add to Java Options “-Dfile.encoding=UTF-8”



Just for the reference . My Tomcat version is 7.0.21, but probably Tomcat 6 and 5 have the same or very similar configuration.

After applying the changes above everything worked like a charm

Technorati Tags: ,,,

No comments:

Post a Comment