I need to get UTF-8 working in my Java webapp (servlets + JSP, no framework used) to support äöå
etc. for regular Finnish text and Cyrillic alphabets like ЦжФ
for special cases.
My setup is the following:
- Development environment: Windows XP
- Production environment: Debian
Database used: MySQL 5.x
Users mainly use Firefox2 but also Opera 9.x, FF3, IE7 and Google Chrome are used to access the site.
How to achieve this?
I want also to add from here this part solved my utf problem:
For my case of displaying Unicode character from message bundles, I don't need to apply "JSP page encoding" section to display Unicode on my jsp page. All I need is "CharsetFilter" section.
To add to kosoant's answer, if you are using Spring, rather than writing your own Servlet filter, you can use the class
org.springframework.web.filter.CharacterEncodingFilter
they provide, configuring it like the following in your web.xml:I'm with a similar problem, but, in filenames of a file I'm compressing with apache commons. So, i resolved it with this command:
it works very well for me. Hope it help anyone ;)
This is for Greek Encoding in MySql tables when we want to access them using Java:
Use the following connection setup in your JBoss connection pool (mysql-ds.xml)
If you don't want to put this in a JNDI connection pool, you can configure it as a JDBC-url like the next line illustrates:
For me and Nick, so we never forget it and waste time anymore.....
One other point that hasn't been mentioned relates to Java Servlets working with Ajax. I have situations where a web page is picking up utf-8 text from the user sending this to a JavaScript file which includes it in a URI sent to the Servlet. The Servlet queries a database, captures the result and returns it as XML to the JavaScript file which formats it and inserts the formatted response into the original web page.
In one web app I was following an early Ajax book's instructions for wrapping up the JavaScript in constructing the URI. The example in the book used the escape() method, which I discovered (the hard way) is wrong. For utf-8 you must use encodeURIComponent().
Few people seem to roll their own Ajax these days, but I thought I might as well add this.