1、 建立服务器
我使用tomcat5.5作为测试环境,建立过程(略);2、 下载struts
可以到http://jakarta.apache.org/struts/index.html下载.3、 建立工程
在webapps目录下建立一个international文件夹,再在international目录下建立web-inf文件夹和web-inf/classes文件夹,这些都是一个jsp工程必须的;4、 加了struts的类
在web-inf目录下建立一个lib子目录,把struts-example/web-inf/lib目录下将所有.jar文件拷贝到该目录下;这些文件是struts的控制类库和标签类库等;commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-fileupload.jar
commons-lang.jar
commons-logging.jar
commons-validator.jar
jakarta-oro.jar
struts.jar
5、 加入struts标签定义文件
从struts-example/web-inf目录下,把.tld文件拷贝到international的web-inf目录下,这些文件标签库的定义文件;struts-bean.tld
struts-html.tld
struts-logic.tld
struts-nested.tld
struts-template.tld
struts-tiles.tld
6、 建立struts的config文件
建立struts的config文件的struts-config.xml,内容如下:"-//apache software foundation//dtd struts configuration 1.1//en" "
http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
7、 建立web.xml文件
public "-//sun microsystems, inc.//dtd web application 2.2//en"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
在classes目录下,建立一个resources目录,用来存放资源文件;
先建立默认的资源文件application.properties和英文(美国)的资源文件application_en_us.properties,内容为:
# -- test --
test.title=international application test
test.body=this is a international application test
先建立这两个文件,中文的等下一步建立
9、建立jsp文件
在这里
启动tomcat,在浏览器里输入http://localhost:8080/international/,查看效果,如果浏览器标题显示international application test,页面里显示this is a international application test则说明你的程序成功了;下面只要增加资源文件,你就可以在多种语言的系统里看了;
10、 建立简体中文的资源文件
在resources目录下建立一个application_cn.properties,输入内容:# -- international test --
test.title=国际化程序测试
test.body=这是一个国际化测试例子
因为java的国际化是通过unicode码来实现,所以要把代码转为unicode码;在dos下,转到resources目录,执行:
native2ascii -encoding gb2312 application_cn.properties application_zh_cn.properties
转换后的application_zh_cn.properties文件内容为:
# -- international test --
test.title=/u56fd/u9645/u5316/u7a0b/u5e8f/u6d4b/u8bd5
test.body=/u8fd9/u662f/u4e00/u4e2a/u56fd/u9645/u5316/u7a0b/u5e8f/u6d4b/u8bd5/u4f8b/u5b50
这就是上面的中文的unicode码;
重新启动tomcat, 在浏览器里输入http://localhost:8080/international/,你看,标题和内容是不是变成中文了;
11、 测试多语言
打开ie的“工具”->“internet选项”菜单,“常规”选项卡,点击其中的“语言”按钮,添加“英语(美国)-[en-us]”语言,将其他的语言删除,重新启动ie后,输入http://localhost:8080/international/index.jsp,你会发现内容已经变成英文.
闽公网安备 35060202000074号