元素类型“formset”的内容必须匹配“(constant *,form +)”

时间:2013-09-27 13:32:13

标签: struts-validation

我收到错误

  

元素类型“formset”的内容必须匹配“(constant *,form +)”

当我执行我的struts应用程序时,它将给出如下错误:

2013-09-27 15:22:35  ERROR org.apache.commons.digester.Digester - Parse Error at line 203 column 15: The content of element type "formset" must match "(constant*,form+)".
org.xml.sax.SAXParseException; lineNumber: 203; columnNumber: 15; The content of element type "formset" must match "(constant*,form+)".
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.commons.digester.Digester.parse(Digester.java:1666)
    at org.apache.commons.validator.ValidatorResources.<init>(ValidatorResources.java:159)
    at org.apache.struts.validator.ValidatorPlugIn.initResources(ValidatorPlugIn.java:237)
    at org.apache.struts.validator.ValidatorPlugIn.init(ValidatorPlugIn.java:162)
    at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:869)
    at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5001)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

我已经如下所示 validation.xml 文件。

<?xml version="1.0" encoding="UTF-8" ?>

<!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">


<form-validation>   
    <global> 
    </global> 
    <formset>        
        <form name="logonForm">
            <field
                property="username"
                depends="registerrequired">
                <arg key="logonForm.username"/>
            </field>

        </form>

      <form name="attachdynamicLookupForm">
            <field 
                property="theFile"
                depends="registerrequired">
                <arg key="attachdynamicLookupForm.to"/>
            </field>

        </form>


        <form name="UserFormBean">
            <field 
                property="username"
                depends="required">
                <arg key="userbean.username"/>
            </field>
            <field
                property="firstname"
                depends="required">
                <arg key="userbean.firstname"/>
            </field>
            <field
                property="lastname"
                depends="required">
                <arg key="userbean.lastname"/>
            </field>
            <field
                property="address"
                depends="required">
                <arg key="userbean.address"/>
            </field>
            <field
                property="city"
                depends="required">
                <arg key="userbean.city"/>
            </field>
            <field
                property="postcode"
                depends="required,mask">
                <msg name="mask" key="userbean.postcode.mask"/>
                <arg key="userbean.postcode"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[0-9a-zA-Z]{6}</var-value>
                </var>
            </field>
            <field
                property="mobileno"
                depends="required,mask">
                <msg name="mask" key="userbean.mobile.mask"/>    
                <arg key="userbean.mobileno"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[0-9]{12}</var-value>
                </var>
            </field>
            <field
                property="email"
                depends="required,email">
                <arg key="userbean.email"/>
            </field>
        </form>

        <form name="DynaUpdateContactForm">
            <field
                property="contactName"
                depends="registerrequired">
                <arg key="dynaupdatecontact.contactname"/>
            </field>
            <field
                property="contactNumber"
                depends="registerrequired,phone">
                <arg key="dynaupdatecontact.contactnumber"/>
            </field>
        </form>
           <!--    resetpassword form   -->
        <form name="DynaResetPassActionForm">
            <field
                property="username"
                depends="registerrequired">
                <arg key="resetpass.username"/>
            </field>
            <field
                property="newpass"
                depends="registerrequired,mask">
                <arg key="resetpass.newpass"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[0-9a-zA-Z]*$</var-value>
                </var>
            </field>
            <field
                property="conpass"
                depends="registerrequired,mask">
                <arg key="resetpass.conpass"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[0-9a-zA-Z]*$</var-value>
                </var>
            </field>
        </form>

        <!--    changepassword form   -->
        <form name="DynaChangePassActionForm">
            <field
                property="oldpassword"
                depends="registerrequired">
                <arg key="changepass.oldpass"/>
            </field>
            <field
                property="newpass"
                depends="registerrequired,mask">
                <arg key="changepass.newpass"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[0-9a-zA-Z]*$</var-value>
                </var>
            </field>
            <field
                property="conpass"
                depends="registerrequired,mask">
                <arg key="changepass.conpass"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[0-9a-zA-Z]*$</var-value>
                </var>
            </field>
        </form>

        <form name="DynaUpdateSenderNameActionForm">
            <field
                property="newsendername"
                depends="registerrequired">
                <arg key="dynaupdatesendername.newsender"/>
            </field>

        </form>

        ///////////////////
        <form name="DynaSMSRequestActionForm">
            <field
                property="req"
                depends="registerrequired,mask">
                <arg key="smsrequest.request"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[ 0-9]+$</var-value>
                </var>
            </field>    
        </form>

    </formset> 

    <!-- An example formset for another locale -->
    <formset language="fr">

        <constant>
            <constant-name>postalCode</constant-name>
            <constant-value>^[0-9a-zA-Z]*$</constant-value>
        </constant>

        <!-- An example form -->
        <form name="logonForm">
            <field
                property="username"
                depends="required">
                <arg key="logonForm.username"/>
            </field>
            <field
                property="password"
                depends="required,mask">
                <arg key="logonForm.password"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[0-9a-zA-Z]*$</var-value>
                </var>
            </field>
        </form>

    </formset>

</form-validation>

3 个答案:

答案 0 :(得分:1)

您的路径中可能还有另一个与验证程序的命名条件匹配的文件。

答案 1 :(得分:1)

很可能由于你在这个

的“////”而遇到麻烦
///////////////////
    <form name="DynaSMSRequestActionForm">

您应该从代码中删除它们,然后重试。希望这会有所帮助。

答案 2 :(得分:0)

如果您在下面看到示例,则将其与您的xml文件进行比较,因为您错过了<var-jstype>内的<var>

请试一试。

<field property="id" depends="intRange">
            <arg key="id" resource="false" />
            <arg key="${var:min}" resource="false" />
            <arg key="${var:max}" resource="false" />

            <var>
              <var-name>min</var-name>
              <var-value>10</var-value>
              <var-jstype></var-jstype>
            </var>

        </field>