struts2中表单的快速验证

1 .包

struts2quickvalidationplugin1.0.jar   放在Web/WEBINF/lib

2.配置

 src/struts.xml package quickValidation;:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "
http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
  <package name="test" namespace="" extends="quickValidation">
   <action name="helloworld" class="actions.HelloWorldAction">
    <result name="index">/index.jsp</result>
    <result name="success">/helloworld.jsp</result>
   </action>
  </package>
</struts>

3.register.jsp中的部份代码

<!-- RapidValidation 表单验证框架开始 -->
 <style type="text/css">
/** 修改验证框架提示文字位置和颜色为同行显示, 字体为蓝色 */
.validation-advice {
 display: inline;
 /* color: blue; */
}
</style>

 <script src="<%=path%>/rapid_validation/prototype_for_validation.js" type="text/javascript"></script>
 <script src="<%=path%>/rapid_validation/validation_cn.js" type="text/javascript"></script>
 <script src="<%=path%>/rapid_validation/effects.js"  type="text/javascript"></script>


 <link rel="stylesheet" type="text/css" href="<%=path%>/rapid_validation/style_min.css" />


 <script src="<%=path%>/prototype-1.4.0.js" type="text/javascript"/>
 <script src="<%=path%>/json.js" type="text/javascript"/>
 <!-- RapidValidation  表单验证框架结束 -->

<s:form action="register.action" οnsubmit="return before();"  cssClass='required-validate'>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" id="regedit_tab">
         <tr>
           <td width="10%" height="40" align="right" class="style3">
            用户名:
            <span class="STYLE5">*</span>&nbsp;
           </td>
           <td colspan="3" valign="middle">
           <s:textfield name="user.userName" label="用户名"
            value="${param['user.userName']}" required="true"
            οnblur="validateName();"
            cssClass="required min-length-6 max-length-20 validate-alphanum" />
          <span id="tip" style="color: red; font-weight: bold"></span>
          </td>
          <td width="40%" class="style4">
           用户名长度为6-20位字符,建议你用手机号码或邮箱注册, 避免用户名重复,而且方便记忆哦!
          </td>
         </tr>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值