Struts2国际化其二

来源:互联网 发布:电脑视频剪切软件 编辑:程序博客网 时间:2024/06/09 23:05

          上次说了Struts2中的加载Action范围的资源文件,这次来说说Struts2的加载全局范围的资源文件。其实只要一个项目有做国际化,一般都会用这一种,因为这个资源文件在整个项目中都是可以使用的。

      首先,创建一个资源文件,规范为resourceName_language_country.properties。然后放到src目录下。然后就是配置文件了。一种有三种方法配置文件。

1.在struts.xml中配置

<constant name="struts.custom.i18n.resources" value="resourceName"></constant>
2.在struts.properties中配置  struts.custom.i18n.resources=resourceName

3.在web.xml中配置

 

    <init-param>      <param-name>struts.custom.i18n.resources</param-name>      <param-value>resourceName</param-value>    </init-param>

最后就是页面中的显示了。可以这样写表单

    <s:form action="admin/Login-login" method="post">      <s:textfield name="username" key="username"></s:textfield>      <s:password name="password" key="password"></s:password>      <s:submit key="submit"></s:submit>    </s:form>
其中key属性来获取资源文件中的key值。

0 0
原创粉丝点击