Struts2国际化文件乱码解决

方法1:使用native2ascii进行编码转换

代码如下:

native2ascii -encoding UTF-8 GlobalMessages.properties NewGlobalMessage.properties

代码说明:

image

然后再在struts.xml中<struts></struts>之间添加如下代码即可,即加入国际化文件:

<constant name="struts.custom.i18n.resources" value="NewGlobalMessage"/>

方法2:安装PropertiesEditor插件

问题
在Struct2在读取语言包properties属性文件时,如果文件中包含中文,会出现乱码。虽然可以native2ascii进行解决,但是使用起来不方便,为了解决这个问题,可以为Eclipse安装PropertiesEditor插件解决这个问题。
步骤
1、Help->Install New Software
在打开窗口“Work with”输入:http://propedit.sourceforge.jp/eclipse/updates/ 然后Enter即可,选择PropertiesEditor进行安装即可。安装过程中,可能有警告,别管它,点击就可以。
2、安装完毕后,重启Eclipse。
3、设置Properties文件和PropertiesEditor关联,如果安装成功,则properties文件图片会变成一个文本中有个绿色的P。如果还不能用Properites Editor打开,则文件右击->Open With->PropertiesEditor即可

原文地址:https://www.cnblogs.com/tufujie/p/5148561.html