Struts1下如何实现国际化
Struts1下如何实现国际化
1.ApplicationResources属性文件的内容如下:
? test.label.title=testTitle
2.在struts-config.xml文件添加如下代码:
? <message-resources key="testResource" parameter="cn/test/ApplicationResources"/>
? testResource为属性文件对应的别名,JSP上用得着。如果有多个属性文件的话,
?? 可以拿来区分。
? cn/test/ApplicationResources:指定属性文件的baseName的路径。
3.JSP中加入标签
? <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
? <bean:message bundle="testResource" key="test.label.title" />?
4.Action如有message的话,可用以下代码读取属性文件的内容
MessageResources messageResources =MessageResources.getMessageResources( cn/test/ApplicationResources); String messageContent = messageResources.getMessage("test.label.title"); ?? 也可以用struts1的方法
?? PropertyMessageResourcesFactory.createResources("cn/test/ApplicationResources");
?