您的位置:首页 > 编程语言 > Java开发

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: