配置VALIDATOR?能否讲详细点.偶是初学.那在成功页怎么写呢.

解决方案 »

  1.   

    1.FormBean中validate方法
    public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) {
         ActionErrors errors = new ActionErrors();
         if(userName == null || userName.length() < 1){
           errors.add("userName",new ActionMessage("userName.error"));
         }
         if(password == null || password.length() < 1){
           errors.add("password",new ActionMessage("password.error"));
         }
         if(code == null || code.length() < 1){
           errors.add("code",new ActionMessage("code.error"));
         }
         return errors;
    }
    2.需要验证的页
    <html:form action="/login">
    用户名:<html:text property="userName" maxlength="20" size="13"/>
           <html:errors property="userName"/> ---property="userName"
                                                 对应上面配置的userName
    密  码:<html:password property="password" maxlength="20" size="13"/>
           <html:errors property="password"/> ---property="password"
                                                 对应上面配置的password
    请输入验证码:
           <html:text property="code" maxlength="4" size="5"/>
           <html:errors property="code"/> ---property="code"
                                                 对应上面配置的code
      

  2.   

    楼上的仁兄.好像是静态验证.我需要的是动态验证.没有loginForm的.没有validate方法
      

  3.   

    让loginForm继承一个org.apache.struts.validator.DynaValidatorActionForm就行了吧