日期:2014-05-17 浏览次数:20637 次
我在试用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"