日期:2014-05-17  浏览次数:20595 次

struts初学者,不会使用<html:errors />
点击下面标题查看本文完整版:struts初学者,不会使用<html:errors />

我在试用struts,想在formbean中进行下数据验证(有哪些字段未填的),所以在formbean中:
? public ActionErrors validate(
? ActionMapping mapping,
? HttpServletRequest request)
? {
?
? ActionErrors errors=new ActionErrors();
? if (this.getUsername().length()==0 ¦ ¦
? ? this.getPassword().length()==0 ¦ ¦
? ? this.getPassword2().length()==0 ¦ ¦
? ? this.getOrganize().length()==0 ¦ ¦
? ? this.getRealname().length()==0)
? {
? ? //System.out.print("form bean: must words\n");
? ? errors.add("haha",new ActionError("user.new.mustwords"));
? ? //request.setAttribute(Globals.ERROR_KEY,errors);
? }
? return errors;
? }
?
? 对应的struts-config:
? <action
? ? attribute="NewuserForm"
? ? name="NewuserForm"
? ? input="/webs/user/newuser.jsp"
? ? path="/newuser"