老规矩 先给个实例:
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 源文件名,目标文件
名