Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Character encoding problem in properties file

 
Sigrid Kajdan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm storing error messages in a properties file and - if necessary - display them in a jsp.
The jsp specifies an encoding of text/html, charset = UTF-8.
In my Eclipse workspace preferences, I specify an encoding of UTF-8 for text files.
Now, I have to use the � character in my properties file. Somehow, Eclipse wants me to use ISO-8859-1 for the properties file ("determined from content"), but if I accept that, it doesn't let me save the file after inserting the � character.
On the other hand, if I change the encoding to UTF-8, the browser will display garbage, even though the jsp is sent as UTF-8.
Things like using a "fresh" properties file or restarting eclipse don't work.

Anybody an idea?
Thank you,
Sigrid
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As part of the deployment, you should use the native2ascii tool to convert UTF-8 property files to ASCII. Then it should work fine. There's also an Ant task that can do this.

Note that the Properties class expects the files it opens to be in ISO-8859-1 (it's hardcoded), so it can't deal with UTF-8 encoded files.
 
Joan Horta Tosas
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was reading that a minute ago. But if you only need the � symbol, you can use € instead. Is what I've always done for not having to do the conversion everytime I change something.
 
Sigrid Kajdan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your help!
I will employ native2ascii in the future.

Just one little question to you, Joan, both your characters appear as � on the screen, so I'd like to ask what did you actually type in - a unicode code point starting with \u...?
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viewing source it looks like euro flanked by & and ; without the spaces

& euro ;
 
Sigrid Kajdan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I see, thanks
 
Joan Horta Tosas
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, sorry, I didn't look at the result on the page
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic