在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那个包里没有
谢谢 !!
博客围绕Struts程序中资源文件中文显示乱码问题展开。执行结果显示中文出现乱码,英文正常。解决方法是创建temp.properties文件,将英文内容拷贝并改为中文,使用native2ascii命令转码生成ApplicationResources_zh.properties文件,同时强调Struts包一个不能少,数据库包需自行添加。
270

被折叠的 条评论
为什么被折叠?



