- 浏览: 455966 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (501)
- java基础 (45)
- struts2 (22)
- WebService (9)
- JavaScript (21)
- Java多线程 (37)
- Hibernate (5)
- Spring (31)
- 数据库 (4)
- 软件设计 (1)
- J2ee (8)
- oracle (2)
- Linux (41)
- Hadoop (1)
- Java集合 (3)
- 设计模式 (3)
- 高并发 (1)
- JVM (15)
- xml (2)
- 数据库事务 (3)
- 动态代理 (1)
- tomcat (9)
- 其他 (4)
- DNS域名 (3)
- CDN (2)
- javaapi (1)
- 编码问题 (6)
- CSS样式 (1)
- TCP学习 (3)
- Java IO (6)
- 常见异常问题 (1)
- 网络编程 (1)
- 开发工具 (5)
- Maven (10)
- ibatis (12)
- Velocity (8)
- Jquery (11)
- HTTP (9)
- 中间件 (3)
- 软件管理 (2)
- Html (2)
- Redis (3)
- 服务器 (1)
- 分布式文件系统 (1)
- 异常 (1)
- 杂谈 (1)
- ICE (4)
- cxf (1)
- Apache ActiveMQ (1)
- 好文 (1)
- Json (1)
- junit (2)
- JMS (1)
- java工具 (1)
- memcache (5)
- 加密解密 (1)
- powerdesigner (3)
- Enterprise Architect (1)
- ide (0)
- hessian (3)
- svn (1)
- xstream (1)
- idea (12)
- HttpClient (2)
- solr (4)
- lucene (2)
- 正则 (2)
- 商品设计 (1)
- poi (1)
- nginx (8)
- java基础;Java集合类 (1)
- javassist (1)
- JMeter (1)
- springmvc (1)
- Java对象序列化 (2)
- java nio (4)
- RandomAccessFile (1)
- socket (1)
- netty (3)
- 博客 (1)
- Spring AOP (7)
- mysql (10)
- 远程调用 (2)
- https (3)
- 加密 (3)
- sql (1)
- git (1)
- webx (1)
- eclipse (1)
- 上传下载 (2)
- log4j (4)
- Mac 系统使用 (6)
最新评论
-
wanxiaotao12:
aswang 写道总结的不错,
正在读《java并发编程实战 ...
Java并发编程实战-学习笔记 -
aswang:
总结的不错, 正在读《java并发编程实战》,看到其中的不变性 ...
Java并发编程实战-学习笔记 -
lianhan3344:
感谢博主分享!!!!
深入剖析Tomcat How+Tomcat+Works中文367页.pdf -
vict0323:
真的是酱紫么?求真相
Spring 实际开发项目中, 是否要default-autowire="byName"
转:http://callan.iteye.com/blog/186014
每种框价都会有国际化的支持,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)方法实现的
getText(String aTextName, String defaultValue), 也可以带参数, 参数的形式可以是String, List, String[]
- 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;
- }
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. 参数化国际化(带参数的), 在properties文件中
在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级优先级最大
发表评论
-
struts2对请求参数的处理
2013-10-10 18:31 623struts2对请求参数的处理 struts2 拦截 ... -
struts2中取得文件的绝对路径的方法
2013-09-30 16:44 1463方法1: [java] view plainc ... -
struts2的ValueStack
2013-06-21 01:03 584Struts2 ValueStack & Acti ... -
struts2中ActionContext应用
2013-06-20 22:38 433struts2中ActionContext应用 -
Struts2源码分析--请求处理
2013-05-12 23:18 658Struts2架构图 请求首先通过Fi ... -
Struts2的运行流程
2013-05-12 23:08 7933.2 Struts2的运行流程 3.2.1 运行 ... -
WebWork框架原理
2013-05-12 12:34 967WebWork的三个关键部分 1、 Actions ... -
Struts2技术内幕-学习
2013-05-05 23:38 12231、MVC只是概念, 我们 ... -
Ognl学习
2013-05-05 16:21 758OGNL框架的使用入门(一) OGNL框架的使用入 ... -
struts2 值栈
2012-12-20 09:48 806值栈(ValueStack)是struts2中的一个重要的 ... -
locale 详解
2012-12-16 00:04 748转:http://daimajishu.iteye.com/b ... -
Struts2 Result-type(封装Action层到View层的跳转逻辑)
2012-12-11 09:14 718http://www.blogjava.net/jzone/a ... -
struts2中常用Result类型的用法
2012-12-10 23:14 666http://zhangxiang390.iteye.com/ ... -
Struts2中使用HttpServletRequest和HttpServletResponse
2012-12-10 22:35 906http://blog.csdn.net/wl_ldy/art ... -
Struts2-Value Stack浅析
2012-12-10 19:24 1297Value Stack的作用: 1. 可以作 ... -
struts2中减少action数量(通配符使用)
2012-12-07 14:50 468http://www.cnblogs.com/netshuai ... -
Struts2中 session的使用
2012-11-11 01:02 794在Struts2里,如果需要在Action中使用session ... -
struts2 架构图及工作流程
2012-10-19 00:43 6551、struts2架构图 2、工作流程 ... -
struts2 action中如何读取国际化资源文件
2012-07-26 22:53 1540action中如何读取国际化资源文件 1、在url地址中使用 ... -
struts2国际化文件的使用
2012-02-01 23:37 1005sturst2国际化资源文件有三种级别从高到低是:类级别(类名 ...
相关推荐
Struts action 国际化 in18
文件的国际化字符串中使用OGNL,格式为${表达式},例如: validation.required=${getText(fileName)} is required 2. 使用java.text.MessageFormat中的字符串格式,格式为{ 参数序号(从0开始), 格式类形(number |...
struts2中的国际化分为3类 Action级别:只能为一个Action服务 资源文件的前缀名和相应的Action同名,而且在同一个包中 package级别:为同包的Action服务 资源文件的前缀必须以package开头,建立在某个包下,表示该包中的...
第11章 理解国际化 240 11.1 Struts 2框架和Java i18n 241 11.1.1 使用ResourceBundle和Locale取得本地化文本 241 11.1.2 Struts 2如何解决本地Java对i18n支持的问题 243 11.2 Struts 2 i18n示例 244 11.2.1 Struts ...
struts2中的国际化 struts2转化器 struts2实现表单数据校验 struts2的基石-拦截器 struts2中实现IOC struts2中实现文件上传 struts2中实现CRUD struts2中的OGNL struts2的新表单标志的使用 struts2与AJAX一 struts2...
本文档包含了struts2的JSP页面、Action类以及校验框架xml的国际化支持
5struts2国际化 ......... 6 struts2输入校验 ......... 7 struts2 OGNL(对象图形化导航语言) ........ 8 struts2拦截器 ......... 9 struts2类型转换 ........ 10struts2标签库 ........ 11、访问数据库 ........
详细介绍Struts2 如何使Action取得属性范围 通配符 国际化等内容,并使用事例说明
如下代码:<s:form action="login2"> 用户名" name="username"/> 密码" name="password"/> 提交"/>我们看着以上的代码跟HTML的差不了多少,但是因为struts2表单默认将表单内的每一个元素都分在单独的一行
·Struts2国际化(i18n)您的应用程序 ·Struts2.0转换器(Converter) ·Struts 2.0中实现表单数据校验(Validation) ·拦截器(Interceptor) ·Struts 2中实现IoC ·Struts 2中实现文件上传 ·Struts 2中的...
Struts2 概述 如何应用Struts2 Struts2 配置文件 如何编写Action 拦截器 Struts2的标签 OGNL 数据校验 国际化
介绍Struts 2及Struts 2开发环境的搭建 第一个Struts 2应用开发 ...配置Action范围国际化资源文件 ognl表达式 Struts 2常用标签解说 使用标签防止表单重复提交 Struts 2+Spring 2.5+Hibernate 3.3整合开发
9.2.2 Struts2Action范围属性文件国际化应用 187 9.2.3 Struts2临时范围属性文件国际化应用 188 9.3 用户主动选择国际化应用介绍 191 第10章 Struts2页面布局实现 194 10.1 sitemesh基本使用方法 194 10.2 sitemesh...
三、 Struts2国际化 35 1、 Action级别 35 2、 Package级别 36 3、 Application级别 36 四、 资源文件中的参数处理 37 五、 国际化-动态语言切换 37 09 自定义拦截器 38 10 类型转换 38 Struts2总结 39
Struts简介 什么是Struts Struts基本运作流程 ActionMapping类 Action类 ActionForm类 ActionError与ActionMessage 协同开发 模块化程序 Struts异常处理 Struts国际化支持 PlugIn接口 等等
1.概述strust2中的拦截器 28 2.自定义拦截器 28 方式一,实现Interceptor接口。 28 方式二、继承AbstractInterceptor抽象类 29 方式三、继承MethodFilterInteceptor类 30 3.使用来MethodFilterInterceptor灵活拦截 ...
该属性指定Struts 2应用所需要的国际化资源文件,如果有多份国际化资源文件,则多个资源文件的文件名以英文逗号(,)隔开. struts.diSPAtcher.parametersWorkaround 对于某些Java EE服务器,不支持HttpServlet Request...
、Struts2 主要几句话: 1、Struts2 是由webwork2 发展来的而非Struts1,相比Struts1,Struts2 编码规范跟类似与webwork2 ...8、Struts2 提供了全局范围、包范围和Action 范围的国际化资源文件管理实现
2.1.4. 消息标记和国际化.15 2.2. 逻辑标记.16 2.2.1. 条件逻辑.17 2.2.2. 重复标记.18 2.2.3. 转发和重定向标记.19 2.3. HTML 标记20 2.3.1. 显示表单元素和输入控件.20 a) 表单标记.21 b) 按钮和取消标记.22 c) ...