对楼主的细心及对这个问题的本身我很感兴趣,主要因为我原先也没注意过这个问题,所以特地试了一下,就是同时用<html:errors/>和<logic:messagesPresent> ,即如下:
<html:errors/>
<logic:messagesPresent>
<bean:message key="errors.header"/>
<ul>
<html:messages id="error">
<li><bean:write name="error"/></li>
</html:messages>
</ul><hr>
</logic:messagesPresent>------------
运行结果是:
Validation Error
You must correct the following error(s) before proceeding: First Name can not be less than 5 characters. Last Name is required. Address is required. City is required. State is required. Zip is required. E-mail is required.
Validation Error
You must correct the following error(s) before proceeding:
First Name can not be less than 5 characters.
Last Name is required.
Address is required.
City is required.
State is required.
Zip is required.
E-mail is required. ----------------------------
可见,采用<html:errors/>时是把所有出错信息简单连在一起显示,而后者是一个信息一个信息地提出来显示,可自由定义每个出错信息的显示方式,上述方式是换行,当前也还可在中间加入别的信息。当然,如果只有一个出借信息,那么上述两者的显示结果是一样的。**************
更重要的一点是,出错信息是采用了setAttribute()函数来保存数据的,所以可以采用各种带有getAttribute()函数来显示,可见出错信息用<logic:Iterate>来提取也是一样的。
可见,在Action、ActionForm、自定义标签文件或其它类文件中也可以直接用setAttribute()函数来保存出错数据。
<html:errors/>
<logic:messagesPresent>
<bean:message key="errors.header"/>
<ul>
<html:messages id="error">
<li><bean:write name="error"/></li>
</html:messages>
</ul><hr>
</logic:messagesPresent>------------
运行结果是:
Validation Error
You must correct the following error(s) before proceeding: First Name can not be less than 5 characters. Last Name is required. Address is required. City is required. State is required. Zip is required. E-mail is required.
Validation Error
You must correct the following error(s) before proceeding:
First Name can not be less than 5 characters.
Last Name is required.
Address is required.
City is required.
State is required.
Zip is required.
E-mail is required. ----------------------------
可见,采用<html:errors/>时是把所有出错信息简单连在一起显示,而后者是一个信息一个信息地提出来显示,可自由定义每个出错信息的显示方式,上述方式是换行,当前也还可在中间加入别的信息。当然,如果只有一个出借信息,那么上述两者的显示结果是一样的。**************
更重要的一点是,出错信息是采用了setAttribute()函数来保存数据的,所以可以采用各种带有getAttribute()函数来显示,可见出错信息用<logic:Iterate>来提取也是一样的。
可见,在Action、ActionForm、自定义标签文件或其它类文件中也可以直接用setAttribute()函数来保存出错数据。
在html:errors的文档中说明,如果定义下面的properties, 可以被自动运用到输出中.
errors.header - Text that will be rendered before the error messages list. Typically, this message text will end with <ul> to start the error messages list.
errors.footer - Text that will be rendered after the error messages list. Typically, this message text will begin with </ul> to end the error messages list.
errors.prefix - Text that will be rendered before each individual error in the list.
errors.suffix - Text that will be rendered after each individual error in the list. 如果:
errors.prefix=<li>
errors.suffix=</li>应该是一样的效果?