我有以下index.jsp:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<fmt:setLocale value="ru_RU"/>
<fmt:setBundle basename="messages"/>
<html>
<head>
<title></title>
</head>
<body>
<h1><fmt:message key="login"/></h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
和属性文件messages_ru_RU.properties:
login = ?????
Run Code Online (Sandbox Code Playgroud)
问题是我在输出中得到了垃圾unicode字符:
Ëîãèí
Run Code Online (Sandbox Code Playgroud)
更新
将.properies文件编码更改为UTF-8.最新产品:Ðогин
请帮助我,将其更改为正常的西里尔字母.
我需要显示一个非英语语言的警告框,我正在使用应用程序资源属性文件来使用bean消息.用JSP编写的代码在Firefox中运行完美,但在IE中字符混乱,我在警告框内得到所有的盒子标志.同样的问题也出现在ToolTips中.有解决方案吗
firefox alert tooltip internationalization internet-explorer-8
我正在尝试从文本文件加载一个属性,但重音字符(saül)有一个不同的编码,而不是UTF-8如何避免它?
我的属性文件有一个带有重音字符的属性(saül).然而,当我远程调试时,我发现了properties.load(bufferedReader); 把它当作saül所以当我写入另一个文件时它被写成saül,我在应用程序的其他地方都有UTF-8编码.从文件中读取属性时,我不确定我做错了什么.
try {
final String propertyFilePath = System.getProperty(JVM_ARGUMENT_NAME);
if (StringUtils.hasText(propertyFilePath)) {
setLocalOverride(true);
resource = getApplicationContext().getResource(propertyFilePath);
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(new FileInputStream(propertyFilePath), "UTF8"));
properties.load(bufferedReader);
externalFilePasswordConfigurer.afterPasswordPropertiesSet(properties);
LOGGER.info("ExternalFilePropertyConfigurer UTF-8 Reader");
}
setProperties(properties);
logProperties(properties);
} catch (Exception e) {
LOGGER.error("ExternalFilePropertyConfigurer setter failed to set properties: ", e);
throw new RuntimeException(e);
}
Run Code Online (Sandbox Code Playgroud) 我在两个不同的系统上得到不同的结果,不知道为什么。
Properties prop = new Properties();
prop.load(new ByteArrayInputStream(input)); //input is byte[]
Run Code Online (Sandbox Code Playgroud)
在两个系统上,输入都包含"var=\\u00C4\\u00DC\\u00D6\\u00E4\\u00FC\\u00F6".
在我的测试系统中,道具包含"var=ÄÜÖäüö". (这就是我要的)
在另一个系统道具上包含"var=\xC4\xDC\xD6\xE4\xFC\xF6". 这是input十六进制的,但为什么Properties要这样做?不幸的是,我对其他系统配置一无所知。
有人知道原因吗?
我正在尝试从.properties文件中读取希伯来语值,我得到了胡言乱语.我尝试了几种方法,包括更改文件的编码(Cp1255,ISO-8859-8,UTF-8),向参数添加-file.encoding并没有任何帮助.
这个问题是在我们从IAS(OC4J容器)迁移到Weblogic期间提出的,我注意到javascript消息(从.properties文件中读取)显示为???? ???,这在OC4J上不会发生.但是,这仅适用于从.properties文件读取的数据,其他所有内容都显示正常.
我一直在谷歌上搜索几天,但我还没有找到解决方案.
编辑:我在家里尝试的
ResourceBundle rb = ResourceBundle.getBundle("test");
System.out.println(rb.getString("test"));
Run Code Online (Sandbox Code Playgroud)
这就是test.properties的样子:
test ????
Run Code Online (Sandbox Code Playgroud)
输出是: ùìåí
我有一个包含以下键和值的属性文件:
elsi.log.status.1 = Keine Änderungen
Run Code Online (Sandbox Code Playgroud)
但是字符 Ä 没有正确显示在我的网页上。输出是 �
但是如果我使用 faces-config 然后直接显示来自 xhtml 的消息,则该消息的显示方式与属性文件中的相同
这是用于从 java 中的属性文件获取值的方法。当我调试时,这里的值已经错了(bundle.getString(key) 返回 Keine �nderungen)
public static String getString(String key) {
try {
Locale locale = CurrentEnvironment.getLocale();
ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale);
if (bundle != null) {
return bundle.getString(key);
}
} catch (MissingResourceException e) {
return '!' + key + '!';
}
return '!' + key + '!';
}
Run Code Online (Sandbox Code Playgroud)
使用 xhtml 直接输出作品
<h:outputText value="#{messages.elsi_copyright}" />
Run Code Online (Sandbox Code Playgroud)
我还注意到用十六进制代码替换属性文件中的字符有帮助,但我想知道是否可以这样做。
谢谢你的帮助