您的位置:首页 > 编程语言 > Java开发

Struts2 的国际化&格式化数据

2011-10-11 11:29 260 查看
国际化的作用就是根据不同国家的用户在访问Web或其他类型的程序时,将各种信息以本地的常用形式显示出来,如界面信息在中国,就会显示中文信息,在以英文为主的国家里,就会显示英文信息。还有就是一些信息的格式,如日期格式等。

1、在SRC下建立 struts.properties 文件、globalMessages_en_US.properties文件和globalMessages_zh_CN.properties 文件

2、修改文件内容struts.properties 文件 中加入以下代码:

struts.custom.i18n.resources=globalMessages以下建立的语言包都以globalMessages开头命名。

定义英文语言包,在globalMessages_en_US.properties 文件中加入以下代码:

#number:

global.format.money={0,number,#0.00##}

global.format.money02={0,number,##0.00}

#datetime:

global.format.date={0,date,yyyy-MM-dd}

global.format.time={0,date,HH:mm:ss}

global.format.datetime={0,date,yyyy-MM-dd HH:mm:ss}

global.format.datetime02={0,date,yyyy-MM-dd HH:mm}

页面上:<s:text name="global.format.date"><s:param value="deployDate" /></s:text>

其中:<s:text name="global.format.date">控制你要显示的时间格式

<s:param value="deployDate" />是你要显示的时间

JSP文件

格式化时间: <s:text name="global.format.date"><s:param value="publishTime"></s:param></s:text>

格式化数字: <s:text name="global.format.money"><s:param value="price"/></s:text>

二:

<input type="text" value="<s:date name="deployDate" format="yyyy-MM-dd" />" />

其中name="deployDate"是你要显示的时间,format="yyyy-MM-dd"是显示的格式

如果不喜欢使用标签的方式,还可以用如下方式取值。,本人更喜欢如下方式,如:

<s:property value="%{getText('global.format.money',{#session.order.productNum})}" />

FROM: http://www.iteye.com/topic/965840

简单案例:http://blog.csdn.net/houqj/article/details/4393132

JSP之数据格式化: http://www.jspcn.net/htmlnews/11500636532961641.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐