struts第十三天--国际化全局访问的国家化资源
2012-10-21 18:10
344 查看
访问国家化资源信息:一是网页上,另外是action中
通过
<constant name="struts.custom.i18n.resources" value="isoftstone"/>就可以办到了。
有时夜目上<s:textfield name="realname" key="welcome"/>可以通过key来访问资源信息。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="isoftstone"/>
<package name="person" namespace="/person" extends="struts-default">
<action name="manage" class="com.isoftstone.study.PersonManagerAction">
<result name="message">/WEB-INF/page/message.jsp</result>
</action>
</package>
</struts>
isoftstone_zh_CN.properties
isoftstone_en_US.properties
package com.isoftstone.study;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class PersonManagerAction extends ActionSupport{
@Override
public String execute() throws Exception {
ActionContext.getContext().put("message", this.getText("welcome"));
return "message";
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>国际化</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<s:text name="welcome"/>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>国际化</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<s:text name="welcome"/>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>国际化</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<s:text name="welcome"/>
</body>
</html>
通过
<constant name="struts.custom.i18n.resources" value="isoftstone"/>就可以办到了。
有时夜目上<s:textfield name="realname" key="welcome"/>可以通过key来访问资源信息。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="isoftstone"/>
<package name="person" namespace="/person" extends="struts-default">
<action name="manage" class="com.isoftstone.study.PersonManagerAction">
<result name="message">/WEB-INF/page/message.jsp</result>
</action>
</package>
</struts>
isoftstone_zh_CN.properties
isoftstone_en_US.properties
package com.isoftstone.study;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class PersonManagerAction extends ActionSupport{
@Override
public String execute() throws Exception {
ActionContext.getContext().put("message", this.getText("welcome"));
return "message";
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>国际化</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<s:text name="welcome"/>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>国际化</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<s:text name="welcome"/>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>国际化</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<s:text name="welcome"/>
</body>
</html>
相关文章推荐
- struts--动态访问国际化资源(国家/语言切换)
- struts 中如何访问资源文件,JSP页面中如何实现国际化显示
- Struts1 和Struts 2 国际化全局资源
- struts 国际化:资源文件访问顺序
- Struts2的国际化、配置全局资源与输出国际化信息、国际化—JSP中直接访问某个资源文件
- struts2国际化---配置国际化全局资源文件并输出国际化资源信息
- struts第十三天--输出带占位符的资源信息
- .NET 中从一个类库中访问资源文件,以实现 ASP.NET 或 ASP.NET MVC 的国际化
- 第二十四章 配置国际化全局资源文件、输出国际化信息
- sturts第十三天--action访问的资源文件的简单访问,或者不指定随意访问
- Android全局资源访问
- 6.Strut国际化动态文本(声明式处理异常):struts-config.xml(全局异常配置)
- struts、spring国际化资源文件使用简介
- Struts 2 之资源国际化
- Struts国际化资源文件中文转码
- struts2.1.8 StrutsPrepareAndExecuteFilter 关于静态资源处理问题。访问classPath下静态资源
- Struts2学习笔记(十六):配置国际化全局资源文件、输出国际化信息
- struts2使用JSP直接访问国际化资源文件
- 国际化全局资源文件输出国际化信息
- Struts 2 之资源国际化