在Struts中可以通过<html:errors/>来显示错误信息,今天简单看了一点,总结一下:
1)如果是采用了formbean的validate的话,首先,struts-config.xml中Action需要加入validate="true"
其实,在Actionform中的validate必须返回一个自己定义的Actionerrors,如例:
public ActionErrors validate(ActionMapping mapping,

HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();

if (this.content.equals(""))
{
errors.add("content", new ActionError("error.user"));
}
return errors;
}2)如果没有采用,而是用Action验证的话,也需要先定义一个Actionerrors,然后再通过
saveErrors(request,errors);把Actionerrrors保存到request中
3)需要注意的
a,每个ActionErrors都有一个String,和一个ActionError构成,ActionError里面的String是和项目资源文件里的一一对应的,String是和html:errors中property相对应的。
posted on 2006-10-30 17:23
rkind 阅读(552)
评论(0) 编辑 收藏