struts2的国际化说明

来源:互联网 发布:红色管弦乐 知乎 编辑:程序博客网 时间:2024/06/07 12:42

struts2的国际化支持还是比较简单的,如下说明:

1、在struts.xml配置文件中配置国际化的资源文档,如我们的资源文档叫message_en_US.properties和message_zh_CN.properties,放到src下的,我们就可以这样配置:

<constant name="struts.custom.i18n.resources" value="<span style="color:#ff0000;"><strong>message</strong></span>"></constant>

message_en_US.properties和message_zh_CN.properties中存放的都是键值对,此处就不多讲了;


2、在jsp中使用国际化

使用struts2的标签库,此处要注意:因为使用的是struts2的标签库,所以必须是经过struts2过滤处理后转向的页面才会有,否则会报未过滤的错误!

The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

在页面引入标签:

<%@ taglib uri="/struts-tags" prefix="s"%>

在文档中使用:

<s:text name="hello"></s:text>

3、在action中使用

这个地方比较简单,直接使用集成的父类ActionSupport中的方法getText()就可以了:

System.out.println(this.getText("hello"));




0 0