Sergio Figueiredo
Sergio Figueiredo

Reputation: 2007

Java literal string: wrong charset at runtime

I am having a charset problem with literal string in Java.

As you can see at image below, I have a static object called TITULO with a literal string constant parameter "Título". When I run the program, this String is readed as "Tí-tulo". I don't know why.

Eclipse Debug View

I explore the charset settings at Eclipse Project Properties Window and Tomcat settings but all them are with UTF-8 as a option.

I'm running Tomcat 7, Eclipse Helios and Windows SO.

Can anyone help me with this issue?

Upvotes: 9

Views: 1163

Answers (3)

Sergio Figueiredo
Sergio Figueiredo

Reputation: 2007

The code that is in eclipse editor is not the same of the code that tomcat is executing.

I found a .war file at /target folder. I deleted this war file and works! The tomcat was running the classes from this old war file.

I have recently converted this running eclipse project to a maven project. I may have executed 'mvn package' at this process that created this war file.

Thanks all for help me found this solution.

Upvotes: 1

Zagrev
Zagrev

Reputation: 2020

You might try setting the Tomcat URIEncoding to UTF-8 in the server.xml

<Connector port="8090" URIEncoding="UTF-8"/>

Upvotes: 1

Guido Simone
Guido Simone

Reputation: 7952

I believe that the string you are looking (this.id) at is not actually the static constant string Titulo.

Somewhere in your code, you are reading the proper unicode String Titulo, converting it to a byte array, then converting it back to a String and passing it to the constructor of Style. The string is getting corrupted during the conversion. Can't say more unless you show the stack trace of the code where you call the constructor of Style.

Upvotes: 0

Related Questions