1.首先是在ActionForm中
ActionErrors errors=new ActionErrors();
if(name==null||name.length()<1){
errors.add("name",new ActionMessage("namewrong"));
}
if(password==null||password.length()<1){
errors.add("password",new ActionMessage("passwordwrong"));
}
if(!password.equals(resetpw)){
errors.add("resetpw",new ActionMessage("resetpasswordwrong"));
}
return errors;
2.在Action中,如果要增加ActionErrors的话
ActionErrors errors=new ActionErrors();
errors.add("name",new ActionMessage("namewrong1"));
this.saveErrors(request, errors);
在jsp页面当中,我们就可以在表单的errors标签中自动显示你所保存的错误了
3.在Action中,如果要增加ActionMessages的话
ActionErrors errors=new ActionErrors();
errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("namewrong1"));
this.addMessages(request, errors);
那么在jsp页面当中,就可以用<html:messages>标签来显示错误信息了
<html:messages id="errors" message="true">
<bean:write name="errors" />
</html:messages>