关注,我这两天也卡在这了。
哪位给个简单点的例子,比如只验证一个text文本框的长度。
validator,和jsp最好都写出来

解决方案 »

  1.   

    偶原来做过一个例子,只验证email的,怎么给你啊
      

  2.   

    验证输入的表单是不是合法的Emaile ,
    package hello;import javax.servlet.http.HttpServletRequest;import org.apache.commons.validator.GenericValidator;
    import org.apache.struts.action.ActionError;
    import org.apache.struts.action.ActionMessage;
    import org.apache.struts.action.ActionMessages;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;public final class HelloForm extends ActionForm {   private String userName = null;   public String getUserName() {       return (this.userName);   }   public void setUserName(String userName) {       this.userName = userName;   }     /**    * Reset all properties to their default values.    */   public void reset(ActionMapping mapping, HttpServletRequest request) {       this.userName = null;   }   public ActionErrors validate(ActionMapping mapping,                                HttpServletRequest request) {       ActionErrors errors = new ActionErrors();            if ((userName == null) || (userName.length() < 1))     errors.add("username", new ActionMessage("hello.no.username.error"));
         
         
         
        /* if(!GenericValidator.isEmail(userName)) {
        errors.add("username", new ActionMessage("hello.no.email"));
    }

    *Validator验证框架包含许多验证方法

       */         return errors;   }}
      

  3.   

    我指的不是像楼上的用acitonForm验证,我想知道的是用validation.xml和validator-rules.xml验证的方法,2楼的可以src、*.xml和*.jsp压一下发到我信箱里(千万不要考lib)[email protected]
    谢谢了
      

  4.   

    三楼的帅哥,我也要,[email protected]多谢了,收到结贴。
      

  5.   

    已发,请查收,[email protected][email protected]
      

  6.   

    非常感谢 wftang 的例子,结贴。