Struts2_textfield标签里显示自定义格式的日期

1.首先在struts.properties或者struts.xml中注册一个国际化资源文件基本名;如下

struts.properties

  struts.custom.i18n.resources=globalMessages

struts.xml

  <constant name="struts.custom.i18n.resources" value="globalMessages" />

 

 

2.然后在你项目目录src下新建你的国际化资源文件对应不同的国家_语言

zh_CN 中文_中国

globalMessages_zh_CN.properties

 

en_US 英语_美国(可选)

globalMessages_en_US.properties

 

 

3.内容(键/值对)

global.datetime = {0, date, yyyy-MM-dd HH:mm:ss}  ##2010-12-20 16:42:25

global.date = {0, date, yyyy-MM-dd}  ##2010-12-20

 

 

4.textfield标签里的使用方法

<s:textfield name="student.birthday" value="%{getText('global.date',{student.birthday})}"/>

 

原理说明:

struts2的资源文件如同其验证文件一样,是允许分散和集中的。使用范围在于Tags和field error中描述信息的查找。整个搜索顺序如下:

  1.  
    1. ActionClass.properties 或者ActionClass_xx_XX.properties
    2. BaseClass.properties
    3. Interface.properties
    4. ModelDriven's model (如果实现了getModel())的类文件
    5. package.properties (包括superclass的package)
    6. search up the i18n message key hierarchy itself
    7. global resource properties

至此!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值