【Struts2系列】Struts2 国际化资源文件的机制原理

时间:2014-08-23 02:27:10   收藏:0   阅读:350

【Struts2国际化资源文件定义的3种范围方法】

 1)全局的国际化资源文件,对所有的Action和View都有效

    定义方式:

        在struts.xml中增加全局资源文件定路径定义:
        <constant name="struts.custom.i18n.resources" value="globalMessage"></constant>

        对应的资源文件为classpath根目录位置:

        globalMessage.properties,

        globalMessage_en.properties,

        globalMessage_cn_ZH.properties

  2)包范围的国际化资源文件,对package目录下的Action和View有效

       不需要额外的配置,只需要将资源文件定义为 :

         package.properties,

        package_en.properties,

        package_cn_ZH.properties,

       并放在对应classpath所在的package目录下      

  3)Action范围的国际化资源文件,只对某个Action以及Action对应的View有效,资源文件已具体的action类名命名,

       如:RegisterAction.class 对应的资源文件为

        RegisterAction.properties, 

        RegisterAction_en.properties,

        RegisterAction_cn_ZH.properties;

       资源文件与Action类放在同一目录位置,不需要额外配置即可生效;

【Struts2国际化资源的引用方式】

 1)在View(JSP)文件中的引用方式

    使用Struts2标签

 2)在Action类中的引用方式

     

        Action的国际化主要是通过getText的三种方法实现的

    public String getText(String aTextName)

    public String getText(String aTextName,List args)

       public String getText(String aTextName,String defaultValue)

   

     如:String str2 = getText("label.hello",new String[]{"kypulo"}); 

本文出自 “开普技术” 博客,请务必保留此出处http://kypulo.blog.51cto.com/9227739/1543672

原文:http://kypulo.blog.51cto.com/9227739/1543672

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!