每种框价都会有国际化的支持,struts2的国际化大致上分为页面的国际化,Action的国际化以及xml的国际化

首先在struts.properties文件中加入以下内容:
struts.custom.i18n.resources=messageResource
或在struts.xml中加入
<constant name="struts.custom.i18n.resources" value="messageResource"></constant>

资源文件的命名格式: 名称_语言代码_国家代码. Properties
如果创建中文和英语国际化,那么资源文件名称为
messageResource_zh_CN.properties和messageResource_en_US.properties

1. jsp页面的国际化 
通过使用标签<s:text name="label.helloWorld"/>输出国际化
label.helloWorld为资源文件中定义的key

在messageResource_en_US.properties加入以下内容
label.hello=hello {0}
label.helloWorld=hello,world

在messageResource_zh_CN.properties加入以下内容
label.hello=你好 {0}
label.helloWorld=你好,世界

(1). <s:text name="label.helloWorld"/>
<s:property value="%{getText('label.helloWorld')}"/>
上面两个都为输出一个hello word的两种表示

<s:textfield name="name" key="label.helloWorld"/>
<s:textfield name="name" label="%{getText('label.helloWorld')}"/>
显示一个文本框,文本框的标题进行国际化

(2). 使用<s:i18n>标签指定从某个特定的资源文件中取数据
<s:i18n name="messageResource">
   <s:text name="label.helloWorld"></s:text>
</s:i18n>
指定在从messageResource取资源

(3).
<s:text name="label.hello">
   <s:param>callan</s:param>
</s:text>
使用带参数的资源.<s:param>可以替换label.hello=hello {0}中的{0}

2. Action的国际化
Action的国际化主要是通过getText(String key)方法实现的

public String execute()throws Exception {   

        // getText(String) string为key  

         String str1 = getText("label.helloWorld");   

         System.out.println(str1);   

        // 带参数的   

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

         System.out.println(str2);   

        // 与上一种实现一样   

         List l = new ArrayList();   

         l.add("callan");   

         String str3 = getText("label.hello",l);   

         System.out.println(str3);   

        return SUCCESS;   

     }

3. 参数化国际化
在messageResource_en_US.properties加入以下内容
userName=userName
userName.required=${getText('userName')} is required

在messageResource_zh_CN.properties加入以下内容
userName=用户名
userName.required=${getText('userName')} 不能为空

在Action中
String str4 = getText("userName.required");
System.out.println(str4);

userName.required=${getText('userName')}会取国际化的用户名

4. 使用校验框价时,提示信息可以国际化
   <field name="userName">
   <field-validator type="requiredstring">
    <message key=”userName.required”> </message>
   </field-validator>
</field>

国际化资源文件分为三种级别
(1) 全局资源文件,可以被整个应该程序引用,也就是struts.custom.i18n.resources=messageResource指定的文件
(2) 包级资源文件,每个包的根目录下可以新建资源文件,仅被当前包中的类访问.文件名格式为:package_语言代码_国家代码.
(3) Action级资源文件,仅被当前Action引用,名称为action名_语言代码_国家代码
查找顺序为从小范围到大范围, Action级优先级最大

<filter>
   <filter-name>struts2</filter-name>
   <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
   <init-param>
            <param-name>struts.custom.i18n.resources</param-name>
            <param-value>globalMessages</param-value>
        </init-param>
</filter>

<filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

struts.custom.i18n.resources国际化的更多相关文章

  1. struts.custom.i18n.resources国际化详解(一)

    每种框价都会有国际化的支持,struts2的国际化大致上分为页面的国际化,Action的国际化以及xml的国际化 首先在struts.properties文件中加入以下内容:struts.custom ...

  2. Java——Struts2 之国际化 struts.custom.i18n.resources=globalMessages

    1.在src下 建立 struts.properties 文件,内容为:struts.custom.i18n.resources=globalMessages struts.custom.i18n.r ...

  3. struts.custom.i18n.resources 如何配置多个资源文件?

    struts.custom.i18n.resources = resources1,resources2,resources3   配置properties文件

  4. (转)在Struts 2.0中国际化(i18n)您的应用程序 + 本人拓展备注

    转:http://www.blogjava.net/max/archive/2006/11/01/78536.html 国际化是商业系统中不可或缺的一部分,所以无论您学习的是什么Web框架,它都是必须 ...

  5. Struts 2 之资源国际化

    首先在struts.properties文件中加入以下内容: struts.custom.i18n.resources=messageResource  或在struts.xml中加入 <con ...

  6. struts中如何实现国际化,涉及哪些文件?

    struts中如何实现国际化,涉及哪些文件? 解答:“国际化”是指一个应用程序在运行时能够根据客户端请求所来自的国家/地区.语言的不同而显示不同的用户界面.Struts框架通过使用<bean:m ...

  7. 菜鸟学Struts——I18N对国际化的支持

    大家肯定都喜欢玩游戏吧. 对于是一个游戏迷的话,肯定玩过不少很棒的经典单机游戏.比方说,国产的<古墓丽影>.<刺客信条>.<鬼泣>国产的仙剑.古剑等.在众多游戏系列 ...

  8. springboot 使用i18n进行国际化

    1.i18n介绍 i18n(其来源是英文单词 internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称.在资讯领域,国际化(i18n)指让产品(出版物,软件,硬 ...

  9. I18n问题 国际化

    http://www.cnblogs.com/guaniu/archive/2012/01/18/2325556.html java国际化 1.了解缺省Locale是由操作系统决定的,Locale是由 ...

随机推荐

  1. AngularJS datepicker 和 datatimepicker

    本文内容 项目结构 AngularJS datepicker AngularJS+jQueryUI datetimepicker 本文介绍 AngualrJS datetimepicker 控件.说明 ...

  2. swift 如何删除subviews

    scrollView.subviews.map { (var view) -> () in if (view is UIButton) { view.removeFromSuperview() ...

  3. git 基本配置及使用

    GIT是个很方便的开发伴侣,这里 随笔记录下GIT工具的基本使用,也希望能帮到别人更快速的使用GIT. 一,安装软件   toroise是最常用也最习惯的工具了,已经是有支持GIT了. 二,生成密钥文 ...

  4. LoadRunner场景参数文件部分参数说明(我在某银行的整理)

    由于场景中脚本繁多,同时设置60个脚本的“运行时设置”会提示个数限制信息,这时可以考虑通过场景的参数文件配置来批量解决这些事情,主要是提高工作效率. 选中自己保存的controller场景,鼠标右键点 ...

  5. 【笔记】《DirectX 9.0 3D游戏开发编程基础》:Direct3D初始化

    Direct3D初始化大概分为4个步骤: 1.获取接口IDirect3D9的指针.(Direct3DCreate9函数调用). 该接口用户获取系统中物理硬件设备的信息并创建接口IDirect3DDev ...

  6. windows 程序设计自学:窗口正中显示Hello,World

    #include <windows.h> LRESULT CALLBACK MyWndProc( HWND hwnd, // handle to window UINT uMsg, // ...

  7. swift 属性

    属性将值和类,结构,枚举相关联.属性分为计算属性和存储属性.存储属性存储常量或变量作为实例的一部分 ,计算属性计算一个值.存储属性用于类和结构体,计算属性用于类,结构体和枚举. 1:存储属性 存储属性 ...

  8. Ubuntu apt命令

    http://www.tecmint.com/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management/ apt-ca ...

  9. Centos用yum升级mysql到(5.5.37)

    原文:http://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/ 1. Change ...

  10. MAC 入门

    1.安装java jdk eclipse 后发现运行不了,原因是JAVA_HOME 没有设置,真操蛋 export JAVA_HOME=`/usr/libexec/java_home` 2.安装bre ...