login 实现国际化(中文、English 【可扩充】)

国际化
原理:把各种不同语言的界面内容写到不同文件去,
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值选资源文件
-->标签读取资源文件


-- login 部分代码实现:
<body>
<a href="emp.do?p=i18n&language=zh_CN">简单中文</a> |
<a href="emp.do?p=i18n&language=en">English</a>

<form action="" method="post">
<table border="0">
<tr>
<td><bean:message key="username"/>:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td><bean:message key="password"/>:</td>
<td><input type=password name="password" /></td>
</tr>
<tr>
<td align="center">
<input type=submit value="<bean:message key='submit'/>" />
</td>

<td align="center">
<input type=reset value="<bean:message key='reset'/>"/>
</td>
</tr>
</table>
</form>
</body>

--具体实现很简单 可下载下面的实例.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值