论坛首页 入门技术论坛

struts 2 的validate.xml 初学

浏览 2192 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-07-18  

<?xml version = "1.0" encoding = "GBK"?>
<!DOCTYPE validators PUBLIC
        "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
        "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
       <!--  2种实现.作用都是一样的. -->
      
<validators>
 <!--  方法1 : 域验证-->
  
 <field name = "username"  >
  <field-validator type="requiredstring">   <!-- 非空验证  -->
   <message key="username is required !"></message>
  </field-validator>
  <field-validator type="stringlength">     <!-- 长度验证  -->
     <param name="minLength">3</param>
              <param name="maxLength">6</param>
              <param name="trim">true</param>
              <message>Your purchase code needs to be XX characters long</message>
  </field-validator>
 </field>
 
 <!--  文字 长度验证  作用同上
 <validator type="stringlength">
              <param name="fieldName">username</param>
              <param name="minLength">10</param>
              <param name="maxLength">10</param>
              <param name="trim">true</param>
              <message>Your purchase code needs to be 10 characters long</message>         
     </validator>-->
 

 <!-- 方法2 : 参数验证 -->
 <validator type="requiredstring">
        <param name="fieldName">password</param>
        <param name="trim">true</param>
        <message>password is required !</message>
    </validator>
</validators>

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics