struts2国际化支持

来源:互联网 发布:第三方软件问题 编辑:程序博客网 时间:2024/06/17 17:13

一、国际化文件的命名

           name_language_country.properties

         name_language.properties

         name.properties

二、在struts.xml文件中配置国际化支持

       

<constant name="struts.custom.i18n.resources" value="name"></constant>

三、在action中使用

public class Hello extends ActionSupport {    public String hello() {        System.out.println("hello");        /**         * 国际化         */        System.out.println(getText("message"));        return SUCCESS;    }}

四、在页面中使用

<%@ page contentType="text/html;charset=UTF-8" language="java" %><%@taglib prefix="s" uri="/struts-tags" %><html>  <head>    <title></title>  </head>  <body><!--第一种用法--> <s:i18n name="msg">   <s:text name="message"></s:text> </s:i18n>
<!--第二种用法-->  <s:text name="message" ></s:text>  </body></html>

五、使用占位符

message = 消息{0}


System.out.println(getText("message",new String[]{"123"}));

0 0
原创粉丝点击