首页 > 解决方案 > cvc-complex-type.2.4.a:发现以元素“位置”开头的无效内容

问题描述

我正在使用 eclipse 版本:Neon.3 Release (4.6.3) 和 Tomcat (v8.5) 进行 Java (JDK1.8) 编程。

我收到一个错误:

cvc-complex-type.2.4.a:发现以元素“位置”开头的无效内容。'{"http://java.sun.com/xml/ns/javaee":error-code, " http://java.sun.com/xml/ns/javaee":exception-type }' 之一是预期的。

我试图解决但没有

这是 web.xml 中的代码

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
     version="2.5" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/servlet-context.xml
    </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>


<filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


<error-page>
    <location>/error</location>
</error-page>

</web-app>

错误显示在location之前的标签上/error

我该怎么做才能解决eclipse错误?

标签: javaxmleclipsetomcatxsd

解决方案


改变你的web-app元素

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
         version="2.5" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                             http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         version="3.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

推荐阅读