关于ActionErrors add函数用法
ActionErrors errors = null;
errors = new ActionErrors();
errors.add("isExist", new ActionError("error.isExist"));
// errors.add("isExist", new ActionError("error.isExist")); 等效于errors.add("isExist", new ActionMessage("error.isExist"));
saveErrors(request, errors);
return (mapping.findForward("failure"));
failure页面里也定义了<html:errors name="isExist"/>
ApplicationResources.properties里面也定义了error.isExist=user have already exist!!!
运行结果 跳转到failure页面,显示“user have already exist!!! ”
------------------------------------<html:errors property="要显示的错误信息"/>
/**ActionErrors和ActionError都是ActionMessage的子类,ActionError存放在
ActionErrors中,ActionError对象中的参数为配置文件中配置的相应的值,若配置文件
中没有配置或配置文件不合适都不能用<html:errors property=""/>输出
*/
1.建立配置文件MyResource.property,例如放在com.gsww.property下.在此配置文件中设定所需要的对应值,如:
# Resources for parameter 'com.yourcompany.struts.ApplicationResources'
# Project P/xioahu
user.name=<b>userName {0} {1} is not valid user,please input again.</b>
login.false=<b>userName or password is not right</b>
2.在struts-config.xml中配置如下:
<message-resources parameter="com.gsww.property.MyResource" />
3.应用如下:
ActionErrors errors = new ActionErrors();
ActionError error = new ActionError("login.false");
errors.add("loginFalse",error);
//saveErrors(request,errors):
return errors; //该段代码可放在相关Form下.如com.qiaoyu.struts.form下的loginForm.java的validate()方法
4.JSP页面中输出错误信息
<html:errors property="loginFalse"/>
ActionErrors errors = null;
errors = new ActionErrors();
errors.add("isExist", new ActionError("error.isExist"));
// errors.add("isExist", new ActionError("error.isExist")); 等效于errors.add("isExist", new ActionMessage("error.isExist"));
saveErrors(request, errors);
return (mapping.findForward("failure"));
failure页面里也定义了<html:errors name="isExist"/>
ApplicationResources.properties里面也定义了error.isExist=user have already exist!!!
运行结果 跳转到failure页面,显示“user have already exist!!! ”
------------------------------------<html:errors property="要显示的错误信息"/>
/**ActionErrors和ActionError都是ActionMessage的子类,ActionError存放在
ActionErrors中,ActionError对象中的参数为配置文件中配置的相应的值,若配置文件
中没有配置或配置文件不合适都不能用<html:errors property=""/>输出
*/
1.建立配置文件MyResource.property,例如放在com.gsww.property下.在此配置文件中设定所需要的对应值,如:
# Resources for parameter 'com.yourcompany.struts.ApplicationResources'
# Project P/xioahu
user.name=<b>userName {0} {1} is not valid user,please input again.</b>
login.false=<b>userName or password is not right</b>
2.在struts-config.xml中配置如下:
<message-resources parameter="com.gsww.property.MyResource" />
3.应用如下:
ActionErrors errors = new ActionErrors();
ActionError error = new ActionError("login.false");
errors.add("loginFalse",error);
//saveErrors(request,errors):
return errors; //该段代码可放在相关Form下.如com.qiaoyu.struts.form下的loginForm.java的validate()方法
4.JSP页面中输出错误信息
<html:errors property="loginFalse"/>