struts 的Validator
struts 的Validator应用需要配置的关键地方.
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>
  <data-sources />
  <form-beans >

    <form-bean name=
"userForm" type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name=
"name" type="java.lang.String" />
    </form-bean>


</form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
  
  <action
    
  attribute=
"userForm"
    
  input=
"post.jsp"
      
  name=
"userForm"
      
  path=
"/user"
    
  scope=
"request"
    
  type=
"com.lunzi.struts.action.UserAction" />


  </action-mappings>

  <message-resources parameter=
"com.lunzi.struts.ApplicationResources" />
  <plug-in className=
"org.apache.struts.validator.ValidatorPlugIn">
    <set-property property=
"pathnames"
    value=
"/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
  </plug-in>
  
</struts-config>

<?xml version=
"1.0" encoding="iso-8859-1"?>
<!DOCTYPE form-validation PUBLIC
          
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
          
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
validation.xml        
<form-validation>
   <formset>
      <form name=
"userForm">
         <field
           property=
"name"
           depends=
"required,,minlength,maxlength">
     <arg0 key=
"label.username"/>    
         <arg1 key=
"${var:maxlength}" resource="false" />
<arg2 key=
"${var:minlength}" resource="false" />
         <var>
           <var-name>maxlength</var-name>
           <var-value>10</var-value>
         </var>
<var>
           <var-name>minlength</var-name>
           <var-value>5</var-value>
         </var>
       </field>          
      </form>            
   </formset>  
</form-validation>
post.jsp

<%@ page language=
"java"%>
<%@ taglib uri=
"http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri=
"http://jakarta.apache.org/struts/tags-html" prefix="html"%>

<html>
<head>
<title>JSP for userForm form</title>
</head>
<body>
<html:form action=
"/user">
name : <html:text property=
"name"/><html:errors property="name"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</htm
lunzi   2006-06-15 14:32:55 评论:0   阅读:1146   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog