CSDN博客

img Arqui

(JavaScript)Validator中javascript的使用

发表于2004/10/12 15:43:00  3118人阅读

   Validator中javascript的使用

1.   
struts-config.xml加入validatorplug-in.

  <!-- Validator的配置-->

  <plug-in className="org.apache.struts.validator.ValidatorPlugIn">

<set-property property="pathnames"

value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>

  </plug-in>

 2.在文件/WEB-INF/validation.xml中是我们要定义自己的验证规则

 <form-validation>

    <!-- ========== Default Global Definitions ===================== -->
     <global>
      <constant>
        <constant-name>userID</constant-name>
        <constant-value>^/d{5}/d*$</constant-value>
      </constant>
      <constant>
        <constant-name>password</constant-name>
        <constant-value></constant-value>
      </constant>
    </global>
   
<!-- ========== Default Language Form Definitions ===================== -->
  
      <formset>

       
        <form name="loginActionForm">
          <field
                property="userID"
                depends="required">
                <arg0 key="login.jsp.prompt.username"/>
             </field>
          <field
                property="password"
                depends="required,mask">
                <arg0 key="login.jsp.prompt.password"/>
            <var>
                <var-name>mask</var-name>
                <var-value>^[0-9a-zA-Z]*$</var-value>
            </var>
         </field>
        </form>
       

    </formset>
   
</form-validation>

3.   在浏览器端使用JavaScript进行验证
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:javascript formName="loginActionForm"/>
<html:html>
<head>
<title><bean:message key="login.jsp.title"/></title>
<html:base/>
</head>
<body>
<html:form action="/loginAction.do" focus="userid" onsubmit="return validateLoginActionForm(this);" method="post">
  <div align="center">
    <table width="22%"  border="4">
      <tr>
        <td height="208"><div align="left">
          <table width="69%"  border="0">
              <tr>
                <td><font color="#000080"><font color="#000000"><bean:message key="login.jsp.prompt.username"/></font><strong>
                  </strong></font></td>
              </tr>
              <tr>
                <td><div align="left">
                  <html:text property="userID" maxlength="40"/>
                </div></td>
              </tr>
              <tr>
                <td height="18"><font color="#000080"><font color="#000000"><bean:message key="login.jsp.prompt.password"/><strong>
                  </strong></font></font>&nbsp;</td>
              </tr>
              <tr>
                <td><div align="center">
                    <html:password property="password" maxlength="10"/>
                </div></td>
              </tr>
                  </table>
          <table width="69%"  border="0">
            <tr>
              <td height="38"><div align="right">
                  <html:submit><bean:message key="login.jsp.prompt.submit"/></html:submit>
              </div></td>
              <td><html:button property="close" onclick="window.close()"><bean:message key="login.jsp.prompt.close"/></html:button></td>
            </tr>
          </table>
   
        </div></td>

    </table>
  </div>

</html:form>

</body>
</html:html>

阅读全文
0 0

相关文章推荐

img
取 消
img