没有得到西班牙字符(ú,í),但在UI上变得像(ï,Ã) [英] Not getting spanish characters (ú, í )but getting like (ó , Ã) on UI
问题描述
我在Strings.properties,Strings_es_ES.properties和Strings_en_GB.properties(适用于美国,ES和英国)的三个属性文件中声明了三个区域转换。
I declared three locale conversions in three properties files like Strings.properties, Strings_es_ES.properties and Strings_en_GB.properties ( for US, ES and UK)
在Strings_es_ES。属性,我声明如下的字符串,并设置属性文件与UTF-8格式。
In Strings_es_ES.properties,i declared the strings like below and set the properties file with UTF-8 format.
admin.main.numberofrewards=Número de recompensas:
admin.main.categorylist=lista Categoría
我使用上述资源捆绑在.jsp文件中,如下所示
I am using the above resource bundle in .jsp files like below
<%@ page pageEncoding="UTF-8"%>
<h2><spring:message code="admin.main.numberofrewards"/></h2>
<p><spring:message code="admin.main.categorylist"/></p>
我在浏览器上输出如下
Nómero de recompensas
lista CategorÃa
请帮助我
推荐答案
并设置UTF-8格式的属性文件
and set the properties file with UTF-8 format
这是您的错误。
href =http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html> 阅读 作为ISO-8859-1,他们因此应保存为ISO-8859-1。如果您要显示 ISO-8859-1字符集无法使用的字符,则您可以基本上有3个选项:
They are read as ISO-8859-1 and they should therefore be saved as ISO-8859-1. If you intend to present characters which are not available by the ISO-8859-1 character set, then you have basically 3 options:
-
使用
native2ascii
工具转换UTF -8保存的属性文件保存到ISO-8859-1编码的属性文件中,其中所有位置都是\uXXXX
的unicode转义,而不是那些不是
Use
native2ascii
tool to convert an UTF-8 saved properties file to an ISO-8859-1 encoded properties file with unicode escapes in form of\uXXXX
over all place instead of those "special characters" which are not covered by ISO-8859-1 charset.
使用自动执行#1的属性文件编辑器,例如Eclipse中构建的属性文件编辑器。换句话说,只需在Eclipse中创建和编辑属性文件。
Use an properties file editor which is capable of doing #1 automagically, such as the one built in Eclipse. In other words, just create and edit the properties file in Eclipse. It'll worry automagically about the encoding.
使用自定义 ResourceBundle.Control
实现,其中您使用显式读取属性文件, new InputStreamReader(inputStream,UTF-8)
。然而,作为非Spring用户我没有线索如何告诉Spring使用自定义控制
。 在JSF中,它很容易。
Use a custom ResourceBundle.Control
implementation wherein you explicitly read the properties file yourself using new InputStreamReader(inputStream, "UTF-8")
. However, as non-Spring-user I have no clue how to tell Spring to use that custom Control
. In JSF it's easy.
另请参阅:
- 网站中的国际化
- Unicode - 如何获得正确的字符? / a>
这篇关于没有得到西班牙字符(ú,í),但在UI上变得像(ï,Ã)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!