欢迎光临
我们一直在努力

JAVA国际化DEMO-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

目录结构:
所有的文件都在包demo下.

mllogin.java
package demo;
import java.util.listresourcebundle;

public class mllogin extends listresourcebundle
{
public mllogin()
{
}

static final java.lang.object[][] contents = {
{ “lblusername”, “lblusername” },
{ “lblpassword”, “lblusername” },
{ “casename”, “lblusername” }
};

public java.lang.object[][] getcontents() {
return contents;
}

}

applicationresource_zh_tw.properties
error.requiredfield=the field is required to save
label.phone=\u96fb\u8a71
label.name=\u540d\u5b57

mllogin_zh_tw.java
package demo;
import java.util.listresourcebundle;

public class mllogin_zh_tw extends listresourcebundle
{
public mllogin_zh_tw()
{
}

static final java.lang.object[][] contents = {
{ “lblusername”, “帳號” },
{ “lblpassword”, “密碼” },
{ “casename”, “登入” }
};

public java.lang.object[][] getcontents() {
return contents;
}

}

formatexample.java

package demo;
import java.util.resourcebundle;
import java.util.locale;
import java.text.messageformat;
/**
*
* @author limohao
*/
public class formatexample {

/** creates a new instance of formatexample */
public formatexample() {
}
public static void main(string [] args){
string ss=”demo.applicationresource”;
resourcebundle bundle=resourcebundle.getbundle(ss);
string requiredfieldmessage =bundle.getstring(“error.requiredfield”);
string [] messageargs=new string[1];
messageargs[0]=bundle.getstring(“label.name”);
string formatnamemessage=messageformat.format(requiredfieldmessage,messageargs);
system.out.println(formatnamemessage);
messageargs[0]=bundle.getstring(“label.phone”);
string formatphonemessage=messageformat.format(requiredfieldmessage,messageargs);
system.out.println(formatphonemessage);
try{
// class test=class.forname(“demo.mllogin”);
// string cname=test.getname();
string cname=”demo.mllogin”;
bundle=bundle.getbundle(cname);
string temp=bundle.getstring(“lblusername”);
system.out.println(temp);
}catch(exception e){
e.printstacktrace();
}
}

}

note:如果是在简体环境下测试可将zh_tw改为zn_cn

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » JAVA国际化DEMO-JSP教程,Java技巧及代码
分享到: 更多 (0)