validator ? Struts Validator???看Struts自带的Samples吧资料看Struts In Action吧可以上CJSDN.net搜索一下,第十二章是讲Validator的

解决方案 »

  1.   

    Struts In Action:
    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {        ActionErrors errors = new ActionErrors();
            if (((name == null) || (name.length() < 1)))
                errors.add("name", new ActionMessage("error.name.required"));
            if(((phone == null)|| (phone.length() < 1)))
                errors.add("phone", new ActionMessage("error.phone.required"));
            if(((address == null)|| (address.length() < 1)))
                errors.add("address", new ActionMessage("error.address.required"));        return errors;    }
    实际没什么的,我觉得,只是两种验证中的Form验证,比较简单,再说明白点就是输入数据格式、是否字母或数字的验证!
      

  2.   

    楼上的,楼主说要用Validator. EASY 啦,用动态的ActionForm 就搞定了,三分钟.不过用字面说不好说。
      

  3.   

    给你一个例子吧:
    Struts 验证:validation.xml
    我们将使用 Struts 提供的输入验证以确保用户在试图登录到应用程序时确实真正地输入了用户标识和密码。验证只是确保用户为两个值输入了某个字符串;实际的认证在我们专为此目的编写的 bean 中进行。(当应用程序被转移到门户环境时将使用门户用户信息,特定于应用程序的登录处理将被删除。)对于我们的输入验证,请使用以下代码来修改 validation.xml。验证需要表单名称、域和验证要求:表单:logonForm 
    域:userName 和 password,两个都要。还有定义了标签名 loginForm.username 和 loginForm.password 的资源属性文件。 
    验证要求:用户在登录表单上输入用户标识和密码。 
    <form-validation>
       <formset> 
         <form name="logonForm">
               <field property="userName"
                      depends="required">
               <arg0 key="loginForm.username"/>
               </field>            <field property="password"
                      depends="required">
               <arg0 key="loginForm.password"/>
               </field> 
          </form> 
       </formset>
    </form-validation>