假设你的属性文件名为ApplicationResources.properties,再建一个名为ApplicationResources_ISO.properties的文件,将要显示的中文全放在ApplicationResources_ISO.properties文件中,ApplicationResources.properties中空白,
然后,把两个文件放在同一目录下,用jdk的native2ascii命令
C:\>native2ascii -encoding gb2312 ApplicationResources_ISO.properties ApplicationResources.properties
该命令的作用是将ApplicationResources_ISO.properties中的中文转换成正则表达式,并将其输入到ApplicationResources.properties中。
然后将ApplicationResources.properties文件拷贝到相应的目录即可。
然后,把两个文件放在同一目录下,用jdk的native2ascii命令
C:\>native2ascii -encoding gb2312 ApplicationResources_ISO.properties ApplicationResources.properties
该命令的作用是将ApplicationResources_ISO.properties中的中文转换成正则表达式,并将其输入到ApplicationResources.properties中。
然后将ApplicationResources.properties文件拷贝到相应的目录即可。
import org.apache.struts.util.*;
import java.util.Locale;
import java.io.*;public class GBKPropertyMessageResources extends PropertyMessageResources {
public GBKPropertyMessageResources(MessageResourcesFactory factory,
String config) {
super(factory, config);
} public GBKPropertyMessageResources(MessageResourcesFactory factory,
String config, boolean returnNull) { super(factory, config, returnNull);
} public String getMessage(Locale locale, String key) {
String msg = super.getMessage(locale, key);
if(null == msg || msg.length() < 1) {
return msg;
}
try {
return new String(msg.getBytes("ISO-8859-1"), "GBK");
}
catch (UnsupportedEncodingException ex) {
return null;
}
}}package my.util;
import org.apache.struts.util.*;public class GBKPropertyMessageResourcesFactory extends PropertyMessageResourcesFactory {
public MessageResources createResources(String config) {
return new GBKPropertyMessageResources(this, config, this.returnNull);
}
}然后在strust-config中配置
<message-resources factory="my.util.GBKPropertyMessageResourcesFactory" parameter="ApplicationResources" />即可!
就是用native2ascii这个命令一转就可以了