在struts中,返回错误信息,出现乱码

在action:
    ...
    ActionMessages messages = new ActionMessages(); 
    messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("id.error")); 
    saveMessages(request, messages); 
    ...
在jsp1.jsp:
...
<logic:messagesPresent message="true">
    <html:messages id="messages" message="true">
        <bean:write name="messages"/>
    </html:messages>
</logic:messagesPresent>
...
在资源文件ApplicationResources:
id.error = 中国人民
--------------------------------------------------------------------------
执行结果:出现乱码,如果(id.error = abcd)就没问题。
请问:如何解决。



大家帮帮忙忙呀。
是不是也要加个中文ApplicationResources_zh文件,内容一样,但不行哦。



你的资源文件没有正确使用。



ApplicationResources.properties是默认资源文件,内容必须是英文的。
如果要用中文,首先建一个temp.properties文件,把ApplicationResources.properties中的英文内容全部拷贝到temp.properties中。然后把temp.properties中的英文全部改为中文。
现在进入命令提示符下,使用java的native2ascii命令进行转码。
c:/>native2ascii temp.properties ApplicationResources_zh.properties
经过这一步,就会生成一个经过编码的资源文件。我们需要的就是它。
把ApplicationResources_zh.properties放在ApplicationResources.properties相同的目录下。
当用户访问网页,需要使用资源文件的信息来显示时,struts会根据用户的浏览器语言选择不同的资源文件来输出信息。
你直接在ApplicationResources_zh.properties和ApplicationResources.properties文件中写上中文是错误的做法。



native2ascii ApplicationResources.properties>>ApplicationResources_zh.properties



C:/j2sdk1.4.2_05/binative2ascii.exe 
PROJECT放的PATH/java/resources/application.properties 
PROJECT放的PATH/java/resources/application.properties



我已按照IceCraft(心淡情浓)的做法,
但报“java.lang.Execption:temp.properties could not be read”。怎改?



按照IceCraft(心淡情浓)的做法,是不是这样做(原来ApplicationResources.properties在D:/JBuilder_WEB/struts_4/struts_4/WEB-INF/classes目录下):
c:/>native2ascii D:/JBuilder_WEB/struts_4/struts_4/WEB-INF/classes/temp.properties ApplicationResources_zh.properties,那么就创建了ApplicationResources_zh.properties文件?



大哥们:怎么转呀?



你看看,在D:/JBuilder_WEB/struts_4/struts_4/WEB-INF/classes/有没有temp.properties这个文件
用下面的方法看看  在命令窗口里执行一下
C:/j2sdk1.4.2_05/binative2ascii.exe D:/JBuilder_WEB/struts_4/struts_4/WEB-INF/classes/ApplicationResources.properties D:/JBuilder_WEB/struts_4/struts_4/WEB-INF/classes/ApplicationResources_zh.properties



好解决了。谢谢大家。

我是我在调第一个struts 程序时看到的一个论坛上的回复我突然明白了我犯的问题

还有就是struts中的包一个都不能少,连数据库的包也要自己加,struts那个包里没有

谢谢 !!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值