1.编写国际化的资源文件:spa
1>.包范围的资源文件(只容许包下面的action访问)
xml
格式:package_language_country.properties
资源
package_zh_CN.properties package_en_US.properties
get
2>.类范围的资源文件:(放到action所在的类路径下)
io
格式:ActionName_language_country.properties
表单
3>全局范围的资源文件(能够被全部的action和JSP访问,通常放到SRC文件下):
配置
格式:BaseName_language_country.properties
方法
注意:全局范围资源文件不是自动加载的,须要配置常量struts.custom.i18n.resources,其值就是BaseName
i18n
可在struts.xml中配置:
struts
<constant name="struts.custom.i18n.resources" value="globalMessage"/>
或者struts.properties中配置:struts.custom.i18n.resources=BaseName
2.访问国际化的资源文件:
1>经过ActionSupport类的getText()方法,其参数name对应着key值,经过key值获取value值
2>标签<s:text name="">标签中name属性即对应key值根据key便可获取value值
3>表单元素中指定一个key值即对应资源文件中的key值,根据key便可获取value值