前段时间,我带实习班的时候,发现他们还在用Struts1.1而且有个同学让我帮他找个错误,死活就是没找到,错误:他的struts-config.xml 资源文件引入:<!--默认的资源文件><message-resources parameter="com.struts.ApplicationResources" /><!--第二个的资源文件--><message-resources className="org.apache.struts.config.MessageResourcesConfig" key="label" id="label" parameter="com.struts.LabelResources" />他有两个资源文件:<!-- ApplicationResources.properties文件下的内容 -->这里有很多validator的验证资源........<!-- com.struts.LabelResources文件下的内容 -->login.username = 用户名login.password = 密码他的validator是这样写的<form-validation><global> <constant> <constant-name>capacityNo</constant-name> <constant-value>^/d{18}/d*$</constant-value> </constant></global><formset> <form name="/saveOrUpdatePatientBaseAction"> <field property="bedNo" depends="required"> <arg0 key="床号" resource="false" /> </field> <field property="capacityNo" depends="required,mask,minlength"> <arg0 key="身份证号" resource="false" /> <arg1 name="minlength" key="${var:minlength}" resource="false" /> <var> <var-name>mask</var-name> <var-value>${capacityNo}</var-value> </var> <var> <var-name>minlength</var-name> <var-value>17</var-value> </var> </field> <field property="patientName" depends="required"> <!-- 注意这里他是从第二个资源文件中取的资源 login.username 也就是用户名 --> <!-- 当然这里写成这样就一定能好使用 <arg0 key="用户名" resource="false"/> 但这样不能国际化 --> <arg0 key="login.username" resource="true"/> </field> </form></formset></form-validation>前台提取的<html:error property="patientName" />时候,提不出来信息"用户名"但后面的,"必需的"几个字提出来了。后来我把ApplicationResources.properties文件中也加入了login.username = 用户名就好用了,接着我又,手工试了在Action中把com.struts.LabelResources中的login.username提出来,在从页面上就可以显示。原来发现validator框架只从ApplicationResources.properties中取值,而不从com.struts.LabelResources取值,随然com.struts.LabelResources已经可以加载。。。注意:以上的平台只是针对Struts1.1和validator1.0,才能出现。