建立一个ApplicationResources_ISO.properties文件,把应用程序用的message都写进去,
然后在dos下执行这个命令,是jdk/bin中的cmd:
native2ascii -encoding gb2312 ApplicationResources_ISO.properties ApplicationResources.properties
这样就会将ISO编码的ApplicationResources转换成GB2312编码的格式了,同时保存到
ApplicationResources.properties。这个文件需要保存在 /WEB-INF/classes目录中
native2ascii这个工具是jdk自带的一个东东,所以如果path都设定正确就可以直接运行了,
你可以在$java_home$/bin下找到他。
转换后的中文类似于这个样子:
iso 格式下 :tj.type=商品车类型
gb2312格式下 :tj.type=/u5546/u54c1/u8f66/u7c7b/u578b
用eclipse中的一个插件,安装些插件通过Eclipse中的软件升级(Software Update)就OK了,下面我们来看一下安装步骤吧:
1、展开Eclipse的Help菜单,将鼠标移到Software Update子项,在出现的子菜单中点击Find and Install;
2、在Install/Update对话框中选择Search for new features to install,点击Next;
3、在Install对话框中点击New Remote Site;
4、在New Update Site对话框的Name填入“PropEdit”或其它任意非空字符串,在URL中填入http://propedit.sourceforge.jp/eclipse/updates/;
5、在Site to include to search列表中,除上一步加入的site外的其它选项去掉,点击Finsih;
6、在弹出的Updates对话框中的Select the features to install列表中将所有结尾为“3.1.x”的选项去掉(适用于Eclipse 3.2版本的朋友);
7、点击Finish关闭对话框;
8、在下载后,同意安装,再按提示重启Eclipse,在工具条看到形似vi的按钮表示安装成功,插件可用。此时,Eclpise中所有properties文件的文件名前有绿色的P的图标作为标识
3修改struts.jar中的org.apache.struts.taglib.bean.MessageTag类
native2ascii用来也是有些麻烦的在文件多的情况下
改页面8859_1(不能是iso-8859-1)可以不用native2ascii转换ApplicationResources.properties
可是没页都要改啊8859_1也很麻烦
所以只好找struts本身来解决了呵呵
struts.jar
org.apache.struts.taglib.bean.MessageTag类
找到doStartTag()方法
里面有行ResponseUtils.write(super.pageContext, message);
在这行上面加上一句 如下
try
{
message = new String(message.getBytes("iso-8859-1"), "gb2312");
}
catch(Exception exception) { }
ResponseUtils.write(super.pageContext, message);
这样就OK了
<%@ page contentType="text/html; charset=gb2312" language="java" %>
要用gb2312