第二十四章 配置国际化全局资源文件、输出国际化信息

本文介绍Struts2框架中的国际化配置方法,包括struts.xml文件的配置细节、不同语言环境下的资源文件设置及如何在页面和Action中调用国际化的文本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>
   <constant name="struts.custom.i18n.resources" value="itcast"></constant>  //配置国际化资源文件 value为文件名
   <package name="itcast" namespace="/test" extends="struts-default">
        <action name="helloworld" class="cn.itcast.action.HelloWorldAction" method="execute" >
			<result name="success">/WEB-INF/page/hello.jsp</result>
        </action>
    </package> 
</struts>

国际化资源文件:

itcast_en_US.properties

welcome =wwww


itcast_zh_CN.properties

welcome =\u6B22\u8FCE


配置完成后,在jsp页面调用:

 <s:text name="welcome"/>

在action里调用,必须继承ActionSupprot类,使用getText()方法调用:

public class PersonManageAction extends ActionSupport{
	public String execute() throws Exceprion{
		ActionContext.getContext().put("message", this.getText("welcome"));
		return "message";
	}
}

在表单标签中使用,通过Key属性指定资源文件中的key:

<s:textfield name="realname" key="user"/>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值