资源文件的使用

老规矩 先给个实例:

ApplicationResource.properties
#这是资源文件: 格式: key= value形式
info.input.account = please input account;

info.input.password = please input password;

#可以传参数,参数用{0},。。。{4}表示
info.input = Please input {0};

#可以写html标签
info.input=<font color = red>please input{0}:</font>
 

#资源文件的中文支持, 新建一个中文的资源文件
并在struct-config中配置新增的资源文件
<!--定义其他资源文件:特意指定key-->
<message-resource  key="CH" parameter = "资源文件名 不带扩展名哦" >

再进行转码转码 native2ascii - encoding gb2312 源文件名 目标文件名

该命令在jdk bin 目录下有, 把含有中文的资源文件进行转码在使用即可


用到资源文件方法;
login.jsp:
<html:form action = "/login">
 <bean:message key="info.input.account/"><html:text property = "account"/><br/>
<bean:message key = "info.input.password"/> <html:password property = "password"/><br>
<html:submit/><html:cancel/>
</html:form><HR>

用到资源文件,传参数方法:
<html:form action = "/login">
 <bean:message key="info.input" arg0="account"/><html:text property = "account"/><br/>
<bean:message key = "info.input" arg0 = "password"/> <html:password property = "password"/><br>
<html:submit/><html:cancel/>
</html:form><HR>

用到资源文件,传参数 用中文方法:
<html:form action = "/login">
 <bean:message key="info.input" arg0="账号" bundle = "CH"/><html:text property = "account"/><br/>
<bean:message key = "info.input" arg0 = "密码" bundle="CH"/> <html:password property = "password"/><br>
<html:submit/><html:cancel/>
</html:form><HR>


理论:

<<bean:message key=key=““消息内容keykey””bundle=bundle=““资源文件keykey””>>
有助于国际化
方法:
––建立一个资源文件
––在strutsstruts--configconfig..xmlxml内指定keykey


<bean:message<message> > 访问资源文件
– Bundle:资源文件keykey
– Key:文件内消息keykey
– ArgNArgN::参数


资源文件的中文支持
native2ascii ––encoding gb2312 源文件名,目标文件


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值