The file cannot be validated as the XML definition 异常解决办法

本文介绍Struts2中配置验证框架的常见错误及其解决方法。通过实例展示如何定义验证规则,包括必填检查、字符串长度限制及字段表达式验证等。

在struts2中配置验证框架时,回报上面的错误。这时候,要学会读懂英文意思。文件不能被验证的XML定义。下面看完整的错误提示。

The file cannot be validated as the XML definition "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd" that is specified as describing the syntax 
 of the file cannot be located.

马上到xwork核心文件中找xwork-validator-1.0.2.dtd的文件的约定规则和自己写的意义对应。

<validators>
    <field name="user.name">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>用户名不能为空</message>      
        </field-validator>

        <field-validator type="stringlength">
            <param name="maxLength">10</param>
            <param name="minLength">6</param>
            <message>用户名长度必须在${minLength}和${maxLength}之间</message>       
        </field-validator>  
    </field>
 </validators>

 <validators>
    <field name="user.pwd">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>密码不能为空</message>       
        </field-validator>

        <field-validator type="stringlength">
            <param name="minLength">6</param>
            <message>长度必须大于${minLength}</message>      
        </field-validator>  
    </field>

    <field name="repwd">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>确认密码不能为空</message>     
        </field-validator>

        <field-validator type="fieldexpression">
            <param name="expression">user.pwd==repwd</param>
            <message>密码和确认密码必须相等</message>      
        </field-validator>  
    </field>
 </validators>

对比发现 是根节点,我多写了。只保留一个就好了。
完整jsp页面代码:

<s:fielderror/>
 <s:form action="reg" method="post">
    <s:textfield name="user.name" label="用户名" />
    <s:password name="user.pwd" label="密码" />
    <s:password name="repwd" label="确认密码" />
    <s:textfield name="user.telephone" label="电话" />
    <s:textfield name="user.username" label="用户姓名" />
    <s:submit value="立即注册" />
 </s:form>

配置文件,配置文件要用请求文件放在一起。命名要注意,如果action命名:RegisterAction,配置文件为:RegisterAction-validation.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
 "-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
 "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd" >

 <validators>
    <field name="user.name">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>用户名不能为空</message>      
        </field-validator>

        <field-validator type="stringlength">
            <param name="maxLength">10</param>
            <param name="minLength">6</param>
            <message>用户名长度必须在${minLength}和${maxLength}之间</message>       
        </field-validator>  
    </field>

    <field name="user.pwd">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>密码不能为空</message>       
        </field-validator>

        <field-validator type="stringlength">
            <param name="minLength">6</param>
            <message>长度必须大于${minLength}</message>      
        </field-validator>  
    </field>

    <field name="repwd">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>确认密码不能为空</message>     
        </field-validator>

        <field-validator type="fieldexpression">
            <param name="expression">user.pwd==repwd</param>
            <message>密码和确认密码必须相等</message>      
        </field-validator>  
    </field>

    <field name="user.telephone">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>电话号码不能为空</message>     
        </field-validator>

        <field-validator type="regex">
            <param name=" regex ">^(\d{3,4}-){0,1}(\d{7,8}))$</param>          
            <message>电话格式不正确</message>      
        </field-validator>  
    </field>

    <field name="user.username">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>用户姓名不能为空</message>     
        </field-validator>

        <field-validator type="stringlength">
            <param name="maxLength">10</param>
            <param name="minLength">2</param>
            <message>用户名长度必须在${minLength}和${maxLength}之间</message>       
        </field-validator>  
    </field>
 </validators> 

acrion

package actions;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

import com.opensymphony.xwork2.ActionSupport;

import entity.User;

public class RegisterAction extends ActionSupport {


        private User user;

        private String repwd;



    public User getUser() {
            return user;
        }

        public void setUser(User user) {
            this.user = user;
        }

        public String getRepwd() {
            return repwd;
        }

        public void setRepwd(String repwd) {
            this.repwd = repwd;
        }


    public String execute(){
        return SUCCESS;

    }   
}
(base) PS D:\cas-env> docker build --no-cache -t cas-final:v1 . [+] Building 17.9s (16/16) FINISHED docker:desktop-linux => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 747B 0.0s => [internal] load metadata for docker.io/apereo/cas:6.6.0 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => CACHED [ 1/11] FROM docker.io/apereo/cas:6.6.0@sha256:dd23e47a15a93256dece4e9ea320080a67298fd9fc0a6f3a63d121c7a5467e03 0.0s => => resolve docker.io/apereo/cas:6.6.0@sha256:dd23e47a15a93256dece4e9ea320080a67298fd9fc0a6f3a63d121c7a5467e03 0.0s => [internal] load build context 6.2s => => transferring context: 146.95MB 6.2s => [ 2/11] RUN rm -rf /usr/local/tomcat/webapps/cas 0.5s => [ 3/11] RUN rm -f /usr/local/tomcat/webapps/cas.war 0.7s => [ 4/11] RUN rm -rf /etc/cas/config/* 0.9s => [ 5/11] COPY target/cas.war /tmp/cas.war 0.5s => [ 6/11] RUN mkdir -p /usr/local/tomcat/webapps/cas && cd /usr/local/tomcat/webapps/cas && jar -xf /tmp/cas.war && rm /tmp/cas.war 2.2s => [ 7/11] RUN mkdir -p /etc/cas/config 0.5s => [ 8/11] COPY src/main/resources/application.yml /etc/cas/config/application.yml 0.0s => [ 9/11] COPY src/main/resources/thekeystore /etc/cas/thekeystore 0.0s => [10/11] COPY src/main/resources/services /etc/cas/services 0.0s => [11/11] RUN chmod -R 777 /etc/cas/services 0.4s => exporting to image 7.6s => => exporting layers 5.8s => => exporting manifest sha256:6704e1cde83466643005a96aad5280677321f6485c6076938d5538dd53070483 0.0s => => exporting config sha256:2aacc2a71ebc8fa7f67569d3ce8d4520b878fbed40ce4e4574415c67c33fc63f 0.0s => => exporting attestation manifest sha256:1898b1619939f7d85fe6c487fe97975aa67c454c7bac203f314ccea5083bae98 0.0s => => exporting manifest list sha256:cce54c96c5f3d4530aa16aac74e13462bcd23f5a9d9b3cf3d556bd2036bf7627 0.0s => => naming to docker.io/library/cas-final:v1 0.0s => => unpacking to docker.io/library/cas-final:v1 1.6s View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/ym1vcttunqzb94vyo9frvw5bo (base) PS D:\cas-env> docker rm -f cas cas (base) PS D:\cas-env> docker run -d --name cas -p 9443:8443 --add-host host.docker.internal:host-gateway cas-final:v1 f52ec2a53d6f62eb09cc40aa8f3e4ae29fa3fc531bfe122ab224b481053d8b6a (base) PS D:\cas-env> docker logs -f cas -e Running CAS @ cas.war /docker/entrypoint.sh: 10: [: false: unexpected operator /docker/entrypoint.sh: 14: [: false: unexpected operator 2025-12-26 05:08:50,949 INFO [org.apereo.cas.configuration.CasConfigurationPropertiesValidator] - <Validated CAS property sources and configuration successfully.> 2025-12-26 05:08:52,489 DEBUG [org.springframework.boot.devtools.restart.Restarter] - <Creating new Restarter for thread Thread[main,5,main]> _ ____ _____ ____ _____ ___ ____ _ ____ / \ | _ \| ____| _ \| ____/ _ \ / ___| / \ / ___| / _ \ | |_) | _| | |_) | _|| | | | | | / _ \ \___ \ / ___ \| __/| |___| _ <| |__| |_| | | |___ / ___ \ ___) | /_/ \_\_| |_____|_| \_\_____\___/ \____/_/ \_\____/ CAS Version: 6.6.0 CAS Branch: 6.6.x CAS Commit Id: cff699f5de01c2a176c311b394447a4513107864 CAS Build Date/Time: 2022-09-04T02:24:14Z Spring Boot Version: 2.7.3 Spring Version: 5.3.22 Java Home: /opt/java/openjdk Java Vendor: Eclipse Adoptium Java Version: 11.0.16.1 JVM Free Memory: 582 MB JVM Maximum Memory: 4 GB JVM Total Memory: 1 GB OS Architecture: amd64 OS Name: Linux OS Version: 5.15.167.4-microsoft-standard-WSL2 OS Date/Time: 2025-12-26T05:08:52.678167 OS Temp Directory: /tmp ------------------------------------------------------------ Apache Tomcat Version: Apache Tomcat/9.0.65 ------------------------------------------------------------ 2025-12-26 05:08:52,734 INFO [org.apereo.cas.configuration.DefaultCasConfigurationPropertiesSourceLocator] - <Configuration files found at [/etc/cas/config] are [[file [/etc/cas/config/application.yml]]] under profile(s) [[standalone]]> 2025-12-26 05:08:52,754 INFO [org.apereo.cas.configuration.loader.YamlConfigurationPropertiesLoader] - <Found settings [[cas.authn.accept.enabled, cas.authn.jdbc.query[0].dialect, cas.authn.jdbc.query[0].driverClass, cas.authn.jdbc.query[0].fieldPassword, cas.authn.jdbc.query[0].password, cas.authn.jdbc.query[0].passwordEncoder.type, cas.authn.jdbc.query[0].sql, cas.authn.jdbc.query[0].url, cas.authn.jdbc.query[0].user, cas.logout.follow-service-redirects, cas.service-registry.core, cas.service-registry.json.location, logging.level.com.zaxxer.hikari, logging.level.org.apereo.cas, logging.level.org.apereo.cas.adaptors.jdbc, server.port, server.servlet.context-path, server.ssl.enabled, server.ssl.key-password, server.ssl.key-store, server.ssl.key-store-password, spring.cloud.config.enabled, spring.main.allow-bean-definition-overriding]] in YAML file [file [/etc/cas/config/application.yml]]> 2025-12-26 05:08:52,890 ERROR [org.apereo.cas.configuration.CasConfigurationPropertiesValidator] - <class org.springframework.core.convert.ConverterNotFoundException cannot be cast to class org.springframework.boot.context.properties.bind.UnboundConfigurationPropertiesException (org.springframework.core.convert.ConverterNotFoundException and org.springframework.boot.context.properties.bind.UnboundConfigurationPropertiesException are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @1a86f2f1)> 2025-12-26 05:08:52,890 INFO [org.apereo.cas.configuration.CasConfigurationPropertiesValidator] - <Validated CAS property sources and configuration successfully.> 2025-12-26 05:08:52,891 INFO [org.apereo.cas.web.CasWebApplication] - <The following 1 profile is active: "standalone"> 2025-12-26 05:08:55,868 DEBUG [org.apereo.cas.tomcat.CasTomcatServletWebServerFactory] - <Code archive: /docker/cas/war/cas.war> 2025-12-26 05:08:55,868 DEBUG [org.apereo.cas.tomcat.CasTomcatServletWebServerFactory] - <Document root: /docker/cas/war/cas.war> 2025-12-26 05:08:58,791 INFO [org.apereo.cas.config.CasCoreServicesConfiguration] - <Runtime memory is used as the persistence storage for retrieving and persisting service definitions. Changes that are made to service definitions during runtime WILL be LOST when the CAS server is restarted. Ideally for production, you should choose a storage option (JSON, JDBC, MongoDb, etc) to track service definitions.> 2025-12-26 05:09:03,663 WARN [org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration] - < Using generated security password: 32531d26-bc1c-41a9-b9ce-294ccabb3162 This generated password is for development use only. Your security configuration must be updated before running your application in production. > 2025-12-26 05:09:03,779 DEBUG [org.apereo.cas.web.security.CasWebSecurityConfigurerAdapter] - <Configuring protocol endpoints [[/login/**, /logout/**, /validate/**, /serviceValidate/**, /p3/serviceValidate/**, /proxyValidate/**, /p3/proxyValidate/**, /proxy/**, /webjars/**, /js/**, /css/**, /images/**, /static/**, /error, /favicon.ico]] to exclude/ignore from web security> 2025-12-26 05:09:04,408 INFO [org.springframework.security.web.access.channel.ChannelProcessingFilter] - <Validated configuration attributes> 2025-12-26 05:09:04,422 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will secure any request with [org.springframework.security.web.access.channel.ChannelProcessingFilter@5cf2f5d6, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@428eb3d5, org.springframework.web.filter.CorsFilter@5ddd84d2, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1640f20f, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@3fd5d679, org.springframework.security.web.access.ExceptionTranslationFilter@12448de1, org.springframework.security.web.access.intercept.AuthorizationFilter@636fccb0]> 2025-12-26 05:09:04,466 DEBUG [org.apereo.cas.web.security.CasWebSecurityConfigurerAdapter] - <Configuring protocol endpoints [[/login/**, /logout/**, /validate/**, /serviceValidate/**, /p3/serviceValidate/**, /proxyValidate/**, /p3/proxyValidate/**, /proxy/**, /webjars/**, /js/**, /css/**, /images/**, /static/**, /error, /favicon.ico]] to exclude/ignore from web security> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/login/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/logout/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/validate/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/serviceValidate/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/p3/serviceValidate/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/proxyValidate/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/p3/proxyValidate/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/proxy/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/webjars/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/js/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/css/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/images/**']> 2025-12-26 05:09:04,466 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/static/**']> 2025-12-26 05:09:04,467 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/error']> 2025-12-26 05:09:04,467 INFO [org.springframework.security.web.DefaultSecurityFilterChain] - <Will not secure Ant [pattern='/favicon.ico']> 2025-12-26 05:09:05,738 WARN [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext] - <Exception encountered during context initialization - cancelling refresh attempt: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'cas-org.apereo.cas.configuration.CasConfigurationProperties': Could not bind properties to 'CasConfigurationProperties' : prefix=cas, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'cas.service-registry.core' to org.apereo.cas.configuration.model.core.services.ServiceRegistryCoreProperties>
最新发布
12-27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值