I am reading an XML file using Scanner scanner = new Scanner(inputStream, "UTF-8"); and then going line by line using scanner.nextLine().
I have some UTF-8 type text in the XML file that I read and it works perfectly when I run my app locally through the Jetty server in my Eclipse Helios IDE.
However when the app is built and deployed on a tomcat server that we use as out dev server, the UTF-8 characters appear as '?' everywhere. When I put some logs in place I found that the characters were being read that way in spite of me mentioning UTF-8 when I initialize the scanner.
I am unable to understand why it would work locally for me but not when I deploy it on tomcat.
I am sure so many might have come across this before.
Are you sure you have tomcat configured to display utf-8?
Have you configured the page displaying it? There is a good how to here How to get UTF-8 working in Java webapps?
Also, have you set the default file encoding to utf-8 in catalina.sh?
-Dfile.encoding=UTF-8"
http://www.redleopard.com/2008/12/utf-8-on-tomcat/
I wouldn't expect it to log utf-8 properly without configuring it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.