struts2 配置带占位符国际化资源(全局)
2011-03-08 20:03
417 查看
1.在src 目录 下添加语言配置文件:
a. orca_en_US.properties
内容:
username=用户姓名
welcome={0}欢迎您到JAVA世界{1}
b. orca_zh_CN.properties
内容:
username=UserName
welcome={0}welcome to JAVA world{1}
2.在struts.xml 中配置(语言文件可以全局访问)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!--
configure properties
value="orca" :值为properties文件的前缀
-->
<constant name="struts.custom.i18n.resources" value="orca" />
<package name="taink" namespace="/control/manager" extends="struts-default">
<action name="employee_*" method="{1}" class="org.taink.struts.action.EmployeeAction">
<result name="input">/index.jsp</result>
<result name="success">/WEB-INF/page/message.jsp</result>
</action>
</package>
</struts>
3.在jsp 页面访问到语言文件, 做以下设置
<%@ taglib uri="/struts-tags" prefix="s"%>
这样就可以通过标签访问了,如下:
信息:
<s:text name="welcome">
<s:param>sany</s:param>
<s:param>study</s:param>
</s:text>
4.在action 中需要访问到语言文件中的信息,如下:
package org.taink.struts.action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class EmployeeAction extends ActionSupport {
private static final long serialVersionUID = 6892944822771610653L;
public String doAdd() {
ActionContext.getContext().put("message", this.getText("welcome",new String[]{"sany","study"}) );
return "success";
}
public String doUpdate() {
ActionContext.getContext().put("message", "更新成功");
return "success";
}
}
a. orca_en_US.properties
内容:
username=用户姓名
welcome={0}欢迎您到JAVA世界{1}
b. orca_zh_CN.properties
内容:
username=UserName
welcome={0}welcome to JAVA world{1}
2.在struts.xml 中配置(语言文件可以全局访问)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!--
configure properties
value="orca" :值为properties文件的前缀
-->
<constant name="struts.custom.i18n.resources" value="orca" />
<package name="taink" namespace="/control/manager" extends="struts-default">
<action name="employee_*" method="{1}" class="org.taink.struts.action.EmployeeAction">
<result name="input">/index.jsp</result>
<result name="success">/WEB-INF/page/message.jsp</result>
</action>
</package>
</struts>
3.在jsp 页面访问到语言文件, 做以下设置
<%@ taglib uri="/struts-tags" prefix="s"%>
这样就可以通过标签访问了,如下:
信息:
<s:text name="welcome">
<s:param>sany</s:param>
<s:param>study</s:param>
</s:text>
4.在action 中需要访问到语言文件中的信息,如下:
package org.taink.struts.action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class EmployeeAction extends ActionSupport {
private static final long serialVersionUID = 6892944822771610653L;
public String doAdd() {
ActionContext.getContext().put("message", this.getText("welcome",new String[]{"sany","study"}) );
return "success";
}
public String doUpdate() {
ActionContext.getContext().put("message", "更新成功");
return "success";
}
}
相关文章推荐
- struts2-19配置国际化全局资源文件、输出国际化信息
- Struts2的国际化、配置全局资源与输出国际化信息、国际化—JSP中直接访问某个资源文件
- Struts2_国际化、配置全局资源与输入国际化信息
- struts2国际化---配置国际化全局资源文件并输出国际化资源信息
- struts2配置国际化全局资源文件 并 输出国际化信息
- 复习struts2之配置国际化全局资源文件、输出国际化信息
- 3.10.1: Struts2的国际化---Struts2中加载全局资源文件
- 第二十四章 配置国际化全局资源文件、输出国际化信息
- struts2配置包范围的国际化资源文件
- struts2配置包范围的国际化资源文件
- Struts2_配置包范围国际化资源文件
- Struts2学习笔记(十六):配置国际化全局资源文件、输出国际化信息
- 复习struts2之配置action范围国际化资源文件
- Struts2简单配置国际化资源文件及用法
- struts2国际化资源的配置
- 配置国际化全局资源文件、输出国际化信息
- struts2配置Action范围的国际化资源文件
- struts2配置Action范围的国际化资源文件
- struts2配置包范围国际化资源文件--包范围
- struts2里资源国际化的配置