(JavaScript)Validator中javascript的使用

   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" οnsubmit="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" οnclick="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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值