cvc-complex-type.2.4.a:从元素'location'开始发现无效内容

我正在使用eclipse Version:Neon.3 Release(4.6.3)和Tomcat(v8.5)来做Java(JDK1.8)编程 .

我收到一个错误:

cvc-complex-type.2.4.a:从元素'location'开始发现无效内容 . 其中一个'{“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>

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

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

回答(1)

3 years ago

从中更改 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">