web.xml文件报错:cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param&

Posted shang神

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了web.xml文件报错:cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param&相关的知识,希望对你有一定的参考价值。

cvc-complex-type.2.4.a: Invalid content was found starting with element ‘init-param‘. One of ‘{"http://
xmlns.jcp.org/xml/ns/javaee":enabled, "http://xmlns.jcp.org/xml/ns/javaee":async-supported, "http://
xmlns.jcp.org/xml/ns/javaee":run-as, "http://xmlns.jcp.org/xml/ns/javaee":security-role-ref, "http://
xmlns.jcp.org/xml/ns/javaee":multipart-config}‘ is expected.

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

报错的servlet节点

 1 <servlet>
 2     <servlet-name>Spring</servlet-name>
 3     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 4     <load-on-startup>1</load-on-startup>
 5     <async-supported>true</async-supported>
 6     <init-param>
 7       <param-name>contextConfigLocation</param-name>
 8       <param-value>classpath:config/spring-servlet.xml</param-value>
 9     </init-param>
10   </servlet>

 

报错提示在第6行

错误提示内容:

cvc-complex-type.2.4.a: Invalid content was found starting with element ‘init-param‘. One of ‘{"http://java.sun.com/xml/ns/javaee":run-as, "http://java.sun.com/xml/ns/javaee":security-
 role-ref, "http://java.sun.com/xml/ns/javaee":multipart-config}‘ is expected.

解决方法:

把4,5行放到9,10行之间,代码如下

 1 <servlet>
 2     <servlet-name>Spring</servlet-name>
 3     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 4     <init-param>
 5       <param-name>contextConfigLocation</param-name>
 6       <param-value>classpath:config/spring-servlet.xml</param-value>
 7     </init-param>
 8     <load-on-startup>1</load-on-startup>
 9     <async-supported>true</async-supported>
10   </servlet>

 

以上是关于web.xml文件报错:cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param&的主要内容,如果未能解决你的问题,请参考以下文章

解决IDEA web.xml 文件报错--: Checks references injected by IntelliLang plugin.

web.xml 文件报错:cvc-id.3: A field of identity constraint ‘.....

eclipse导入web项目,web.xml报错

servlet 中web.xml在eclipse下报错?

idea中,使用facets添加完web后,项目已变为web项目,但web.xml中内容经常变为红色,并报错,如何解决?

eclipse 运行jsp 配置文件web.xml中的async-supported报错解决办法