3.struts1.x的国际化

 国际化要对就资源文件,这必须在struts-config.xml中指定,与struts2中则不需。

 配置方法:

    <message-resources parameter="edu.yzu.resources.messages" ></message-resources>

    <message-resources parameter="edu.yzu.resources.information" key="information" ></message-resources>

    其中第一种配置为默认配置,没有指定其key属性,则struts会自动将其key设为org.apache.struts.action.MESSAGE,源码可查,且一旦要使用资源文件则一定要有一个不能有key属性,即一定要给org.apache.struts.action.MESSAGE指定一个资源文件,struts默认此资源文件为全局资源文件,即以后使用资源文件的地方若没有指定其使用哪个文件,则会从这个默认配置资源文件中找。Struts会将资源文件打包MessageResourcesConfig以key值为键放在ServletContext的作用域中,在其它使用到资源文件的地方可以key值指定使用哪个资源文件中的键值对;

类型转换                                      

  1. struts的页面的国际化

使用<bean:message bundle="information" key="errors.validwhen" arg0="param1" arg1="param2"/>

Bundle指定是使用哪个资源文件,即在资源文件配置时指定的key值。

Key为资源文件中的键值。

Arg0,arg1指若资源文件中有占位符时用来替代的值。

  1. struts的异常的国际化

        <!--

            key指定信息在资源文件中的键值

            type指发生的异常类型。

            bundle使用哪个资源文件,不配置则使用默认的资源文件

             -->

            <exception key="user.register" type="edu.yzu.exception.UserRegisterException" bundle="exception" path="/error.jsp"/>

  1. struts的输入验证的国际化

配置:
<field property="userName" depends="required">

            <!-- msg的key值为资源文件中键值,name指定这个消息为哪个验证器指定,

            因为一个field可以同时指定几个验证器。

            bundle指定使用哪个资源文件,这个值在资源文件配置时被指定为key值。

            arg用来代替信息中的点为符

             -->

                <msg key="errors.required" name="required" bundle="information"/>

                <arg position="0" key="userName" resource="false" />

</field>

 

 

posted @ 2010-05-03 16:40  沉兮  阅读(458)  评论(0编辑  收藏  举报