当前位置: 代码迷 >> Web前端 >> struts第十三天-国际化大局访问的国家化资源
  详细解决方案

struts第十三天-国际化大局访问的国家化资源

热度:33   发布时间:2012-10-24 14:15:58.0
struts第十三天--国际化全局访问的国家化资源

访问国家化资源信息:一是网页上,另外是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>

 

  相关解决方案