Difference between errortag and message tag
By Ramakrishna on Oct 5, 2008 in Struts Interview Questions
Q) What is the difference between errorstag and message tag?
Rep) Errorstag genereates the error
for Ex:
<%@ taglib uri=”/tags/struts-html” prefix=”html” %>
O/P of rs.jsp
</html:errors/>
When the errors tag is evaluated a list of error message will be generated based on the ActionError objects available in ActionError objects available in ActionErrors object. while generating the list of errors the errors tag uses the message resources with the keys Errors.header,Errors.prefix,Errors.suffix and Errors.footer.
This forces us to use the html tags as part of the properties file which is not a good practice. As an alternative to the errors tag messages tag is provided to use themessage tag we need not provide the html tags in the properties file.
re.jsp
<%@ taglib uri=”/tags/struts-bean” prefix=”bean” %>
<html:messages id=”msg”>
<li><bean:write name=”msg”/>
<li>
</html:messages>
</ul>
preffering message will be better than using the error tag because it saves time errors tags
some messages recognize in the pro since which allows to make use of html tags
As an alternative for save errors method,save messages() method is provided as an alternative to action errors;ActionMessages’ class is provided
one.jsp :-
<ul><html:messages id=”msg” message=”true”>
<li><bean:write name=”msg”/>
<li></html:message></ul>
If we use ActionMessage objects in place of ActionError objects we must specify message=true in the message given(tag)
