军功中心显示密码错误:struts2国际化

来源:百度文库 编辑:中财网 时间:2024/05/11 15:37:58

java底层的国际化原理:

1、先在src目录下创建相应的若干个属性文件:查看java.util.Local类java.util.ResourceBundle类,java.text.MessageFormat类。

格式:baseName_language_country.properties

比如:美国的英文的属性文件:hello_en_US.properties  (注意大小写)

     中国的中文的属性文件:hello_zh_CN.properties  (注意大小写)

    在属性文件中不允许输入中文保存,应该用native2ascii进行将中文进行转换成unicode编码的格式进行保存。

如果资源文件需要接收程序外部传入的参数进行动态显示,则需要在资源文件的value后面写上 :{0} 参数,当然也可以加多个参数,比如 :{0}{1}。如果是多个参数。则传递的参数也需要多个

hellofile_en_US.properties:

  hello = hello world:{0}{1}

 

hellofile_zh_CN.properties:

  hello = \u60a8\u597d:{0}{1}

 

2、创建一个java的测试文件。

package com.test.i18n;

import java.text.MessageFormat;

import java.util.*;

public class Test3 {

   publicstatic void main(String[] args) {

//得到当前系统默认语言的一个实例

     Localelocale = Locale.getDefault();

      //得到美国语言的本地化的一个实例

      // Locale locale2 = Locale2.US

     ResourceBundlebundle = ResourceBundle.getBundle("hellofile",locale);

     // ResourceBundle bundle2 =ResourceBundle.getBundle("hellofile",locale2);

     Stringvalue = bundle.getString("hello");

    // String value2 = bundle2.getString("hello");

     //将object数组中的参数传递给资源文件中的第一个变量,就会将"北京",”上海”替换掉资源文件中的{0}{1}

     Stringresult = MessageFormat.format(value, new Object[]{"北京","上海"});

// String result2 = MessageFormat.format(value2,new Object[]{"北京","上海"});

 

     System.out.println(result);

//System.out.println(result2);

    

   }

}

 

运行它:输出结果为  您好:北京上海

运行注释的代码结果为:hello word:北京上海

 

struts2的国际化:有四种(类型转换消息的国际化、数据据校验信息的国际化、JSP显示页面的国际化、Action里面准备输出信息的国际化)

1、           JSP页面的国际化:

先在struts.xml中的标签中加入一句:

再在src下面创建两个(或更多)名为message的资源文件

message_zh_CN.properties:

addUser = \u589e\u52a0\u7528\u6237\u4fe1\u606f

message_en_US.properties:

addUser = Add User Information

最后在jsp页面中需要提示信息的地方,加上一句:

addUser”>

 

2、