你在配制文件里面加载了这个validate.xml文件吗?

解决方案 »

  1.   

    写了,
    我的代码大概如下:
    链接:
    <a href="amendPhoneRecord.do?recordPhoneID=<bean:write name='rh' property='id'/>">
      <bean:message key="showphonerecord.jsp.amend" /> 
    </a>
    接收链接的Action:
    int recordPhoneID = Integer.parseInt((String)request.getParameter("recordPhoneID"));//获取记录ID号
    DataBaseBean db = new DataBaseBean();//数据库操作对象
    PhoneRecord pr = db.takePhoneRecord(recordPhoneID);//调用takePhoneRecord方法,获取用户资料的对象
    AmendPhoneRecordActionForm apra = new AmendPhoneRecordActionForm();//创建一个form;
    apra.setRecordPhoneID(pr.getId());//ID
    ...
    ...这里赋值给Form
    ...
    request.setAttribute("amendPhoneRecordActionForm", apra);//放入请求对象
    return mapping.findForward(ManipulationHabitus.SUCCESS);//转发#显示内容的JSP:
    <logic:present name="amendPhoneRecordActionForm" scope="request">
      <html:form action="/saveAmendPhoneRecrod.do" method="POST">
        <table width="70%" border="0">
         ...
         ...一些<html:text property="workFunction" size="20" />之类的Form属性对应的<html:text>
         ...
        </table>
      </html:form>
    </logic:present>#struts-config.xml里的配置为:
    <!-- 修改记录 -->
    <action path="/amendPhoneRecord" scope="request"
    name="amendPhoneRecordActionForm"
    type="com.addressbook.struts.action.AmendPhoneRecordAction">
      <forward name="success" path="/amendphonerecord.jsp" />
    </action>
    <!-- 保存修改后的记录 -->
    <action input="/amendphonerecord.jsp"
    path="/saveAmendPhoneRecrod"
            scope="request" validate="true"
    name="amendPhoneRecordActionForm" 
            type="com.addressbook.struts.action.SaveAmendPhoneRecrodAction">
      <forward name="success" path="/errormessage.jsp" />
      <forward name="failre" path="/errormessage.jsp" />
    </action>#这里是validator.xml里的验证配置
    <!-- 修改记录页面验证 -->
    <form name="amendPhoneRecordActionForm">
    <field property="recordName" depends="required">
    <arg0 key="Label.recordName" resource="true" />
    </field>
    <field property="birthday" depends="date">
    <arg0 key="Label.birthday" />
    <var>
    <var-name>datePattern</var-name>
    <var-value>MM/dd/yyyy</var-value>
    </var>
    </field>
    <field property="mobilePhone" depends="mask">
    <arg0 key="Label.mobilePhone" resource="true" />
    <msg name="mask" key="errors.mask" resource="true" />
    <var>
    <var-name>mask</var-name>
    <var-value>^[0-9]*$</var-value>
    </var>
    </field>
    <field property="mobileTelePhone" depends="mask">
    <arg0 key="Label.mobileTelePhone" resource="true" />
    <msg name="mask" key="errors.mask" resource="true" />
    <var>
    <var-name>mask</var-name>
    <var-value>^[0-9]*$</var-value>
    </var>
    </field>
    <field property="telePhone" depends="mask">
    <arg0 key="Label.telePhone" resource="true" />
    <msg name="mask" key="errors.mask" resource="true" />
    <var>
    <var-name>mask</var-name>
    <var-value>^[0-9]*$</var-value>
    </var>
    </field>
    <field property="workUnitPhone" depends="mask">
    <arg0 key="Label.workUnitPhone" resource="true" />
    <msg name="mask" key="errors.mask" resource="true" />
    <var>
    <var-name>mask</var-name>
    <var-value>^[0-9]*$</var-value>
    </var>
    </field>
    <field property="QQ" depends="mask">
    <arg0 key="Label.QQ" resource="true" />
    <msg name="mask" key="errors.mask" resource="true" />
    <var>
    <var-name>mask</var-name>
    <var-value>^[0-9]*$</var-value>
    </var>
    </field>
    <field property="email" depends="email">
    <arg0 key="Label.email" resource="true" />
    </field>
    </form>
    </formset>但是不知道是怎么回事,验证就是起不到作用.
      

  2.   

    #这里是保存修改记录的代码:
    AmendPhoneRecordActionForm apra = (AmendPhoneRecordActionForm)form;//得到Form
    int genusId = ((Integer)request.getSession().getAttribute("UserID")).intValue();

    //填充对象
    PhoneRecord pr = new PhoneRecord();
    pr.setId(apra.getRecordPhoneID());
    pr.setRecordName(apra.getRecordName());
    pr.setSex(apra.getSex());
    pr.setBirthday(apra.getBirthday());
    pr.setMobilePhone(apra.getMobilePhone());
    pr.setMobileTelePhone(apra.getMobileTelePhone());
    pr.setTelePhone(apra.getTelePhone());
    pr.setWorkUnitPhone(apra.getWorkUnitPhone());
    pr.setQQ(apra.getQQ());
    pr.setEmail(apra.getEmail());
    pr.setFamilyAddress(apra.getFamilyAddress());
    pr.setCompany(apra.getCompany());
    pr.setWorkAddress(apra.getWorkAddress());
    pr.setWorkFunction(apra.getWorkFunction());
    pr.setGenusId(genusId);//将Session里的UserID赋值给它
    pr.setAssortId(Integer.parseInt(apra.getAssortId()));//这里要记得转换成整形

    //调用数据库修改记录的方法
    DataBaseBean db = new DataBaseBean();
    HashMap hm = db.amendPhoneRecord(pr);
    if(((String)hm.get("ManipulationHabitus")).equals(ManipulationHabitus.SUCCESS)){
    String message = (String)hm.get("Message");
                String path = "transact.do";
                String linktext = "返回";
                request.setAttribute("Message", message);
                request.setAttribute("Path", path);
                request.setAttribute("LinkText", linktext);
                return mapping.findForward(ManipulationHabitus.SUCCESS);
    }else{
    String message = (String)hm.get("Message");
                String path = "queryphonerecord.jsp";
                String linktext = "返回查询页面";
                request.setAttribute("errormessage", message);
                request.setAttribute("Path", path);
                request.setAttribute("LinkText", linktext);
                return mapping.findForward(ManipulationHabitus.FAILURE);
    }
    }功能都已经实现了,并且运行良好,但是就是当我把合法的数据改成不合法的数据,amendPhoneRecordActionForm(对应修改后数据的Form)它不验证了.
      

  3.   

    已经解决了,原来是我的Form没有用 ValidatorForm,犯了一个低级错误