Reputation: 1107
I have a Struts 2 application which has a Spanish property file used by Struts s:text tags. However, the resulting pages in the web browser have gibberish characters in them like this:
Contraseña:
The value in the property file is:
password = Contraseña
I initially thought that the problem was the encoding of my property file, but both Notepad++ and standard Windows notepad report that it is saved as UTF-8.
Is there anything else that I could do to fix the characters in my property files?
Upvotes: 1
Views: 780
Reputation: 1741
Your problem is that the properties files are, by default, readed asuming that the encoding is ASCII, something that, really, sucks.
I've an unanswered question here regarding the same problem.
I know that ResourceBundle can manage UTF-8 files (I say in that question how to do it and put a link to a page in which is done and used un JSF) but no idea of how to do it in struts2
Upvotes: 0
Reputation: 8169
The issue is with the browser, you should serve those characters as HTML entity
like :
ñ
, you may want to write them that way directly or have an tool to convert those values to HTML entities
.
Also in the files to avoid issues with other developers and editors with not UTF8
, the best way is to store those string in Unicode
format, you can type them in your native language (Spanish for example) and after that run the native2ascii
command to convert them to unicode
...
The advantage with that is that everyone will be able to open the .java
and .jsp
files... if they want to work with the phrases, then they open the properties file...
Upvotes: 1