国际化
原理:把各种不同语言的界面内容写到不同文件去,
struts自动读取。
步骤:
一.实现国际化资源文件(实现几种语言就要实现几个资源文件)
1.在哪个建资源文件
看struts-config.xml中的<message-resources
parameter="com.yourcompany.struts.ApplicationResources" />
在com.yourcompany.struts包下
2.资源文件如何命名
默认自成ApplicationResources.properties
从ie的工具-->选项-->语言,找自己
a)如中文看到是:zh-cn
这样命名:ApplicationResources_zh_CN.properties
b)日语:ja-JP
ApplicationResources_ja_JP.properties
c)
ApplicationResources_en.properties
3.资源文件内容写什么
键值对形式存在(左边键,英文)
右边的内容如何确定?unicode编码(双字节)
a) 如果myeclipse>=6.5
直接添加
b) 如果myeclipse<6.5
要安装一个插件.并重启myeclipse
右击资源文件open with,选绿色
二.在界面用标签读取资源文件
界面读取bean标签
<%@taglib prefix="bean" uri="/WEB-INF/struts-bean.tld">
<bean:message key="username"/>
三.切换语言
ie浏览器上传选择语言-->struts接收
-->保存语言到session(这步做文章)-->根据session值选资源文件
-->标签读取资源文件
request.getSession().setAttribute(
Globals.LOCALE_KEY, Locale.CHINESE);