lyyb2001

只是为方便自己找记录而已
posts - 57, comments - 27, trackbacks - 0, articles - 5
  BlogJava :: 首页 :: 新随笔 :: 联系 ::  :: 管理

struts处理国际化问题

Posted on 2007-04-30 17:43 skycity 阅读(387) 评论(0)  编辑  收藏 所属分类: MVC框架

处理国际化问题得在先配置好struts的环境下才能进行的,关于如何配置struts环境,网上搜一下,已经一大巴了,没必要我再在这里罗嗦了。
主要说明一下如何解决struts下恶国际化问题,刚摸索这个问题的时候走了很多错路,害我整了一两个小时,写下来主要是为了以后自己或者初学的人不要再走错路。
真正要实现struts国际化很简单。
struts国际化访问的都是目录下的properties资源文件。我们先建几个资源文件
ApplicationResource_zh.bak(中文源文件)
index.jsp.welcome=你好
index.jsp.userid=用户编号
index.jsp.pass=用户密码
建Application_en.properties
index.jsp.welcome=welcome
index.jsp.userid=User ID
index.jsp.pass=Password
现在将ApplicationResource_zh.bak转换为unicode编码的文件
native2ascii -encoding -GBK ApplicationResource_zh.bak ApplicationResource_zh_CN.properties
native2ascii -encoding -Big5 ApplicationResource_zh.bak ApplicationResource_zh_TW.properties
注意:资源文件的命名规则:ApplicationResource_国家_语言。还有千万注意大小写。我自以为是的吧zh弄成大写,害我整了好久都没效果,真是丢脸
接着可以在struts-config.xml中配置资源文件
 <message-resources parameter="net.skycity.ApplicationResource" />
jsp中头部设置为:
<%@ page contentType="text/html; charset=UTF-8"%>
默认国际化
<%@ taglib uri="/struts-bean" prefix="bean"%>
<%@ taglib uri="/struts-html" prefix="html"%>
<%@ taglib uri="/struts-logic" prefix="logic"%>
<%@ page import="org.apache.struts.Globals"%>
<html:html locale="true">
 <bean:message key="index.jsp.welcome"/>
</html:html>
变更不同的国家,可以在浏览器的工具—>Internet选项->语言设置
刷新页面,就会显示不同国家的资源文件名



Lyyb2001

只有注册用户登录后才能发表评论。


网站导航: