每种框价都会有国际化的支持,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. 【转载】UEditor前端配置项说明

    UEditor 的配置项分为两类:前端配置项 和 后端配置项 后端配置项具体看这个文档L:后端配置项说明 本文档介绍如何通过设置前端配置项,定制编辑器的特性,配置方法主要通过修改ueditor.con ...

  2. 面包板入门电子制作(class1)视频 全套30集高清

    面包板入门电子制作(class1)套件(30集高清) 本套件以电子制作中最基础的元器件在面包板上搭建电路,用启发性的视频教学方式,使学习者熟悉电子电路基础.发挥想像力.在创新设计和制作中学会独立设计和 ...

  3. Scala 深入浅出实战经典 第65讲:Scala中隐式转换内幕揭秘、最佳实践及其在Spark中的应用源码解析

    王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...

  4. Crystal Reports "Access to report file denied. Another program may be using it."

    I encounter this problem several times, the way to get around this is to give "Everyone or Netw ...

  5. android 开发 - 对图片进行虚化(毛玻璃效果,模糊)

    概述 IPAD,IPHONE上首页背景的模糊效果是不是很好看,那么在 Android中如何实现呢.我通过一种方式实现了这样的效果. 开源库名称:anroid-image-blur 一个android ...

  6. jQuery诞生记-原理与机制

    一.看似偶然的东西实际是必然会发生的 我大学时候在图书馆翻过一本很破旧的书,讲生物理论的,主要内容就是探讨生命的产生是偶然还是必然.里面很多亚里士多德都看不懂的公式计算什么的,还有模拟原始地球环境出现 ...

  7. C# 调用百度地图Web服务API

    最近公司项目中需要根据两个地点的交通路径和距离做一些数据推荐,为了程序的稳定和用户体验所以想从百度地图 API 采集数据保存到数据库中,经过一翻研究之后选定了百度地图 Web 服务 API 中的 Di ...

  8. React Native ——实现一个简单的抓取github上的项目数据列表

    /** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; var React ...

  9. [翻译]使用Swift在Xcode中创建自定义控件

    使用Swift在Xcode中创建自定义控件 原文 IBDesignable and IBInspectable With IBDesignable and IBInspectable, develop ...

  10. ios 关于文件操作 获取 文件大小

     分类: Apple IPhone2012-06-28 11:31 4664人阅读 评论(0) 收藏 举报 ios语言manager测试c c语言 实现 #include "sys/stat ...