element XXX is not allowed here的错误。网上很多说重启idea或者Tomcat的jar包配置的,真是希望自己试一下再转帖啊,几篇错误的能抄的到处都是,害人害己啊。

1、注意比对web.xml的头文件格式是否正确。

web.xml文件头声明各个版本参考

Servlet 3.1

Java EE 7 XML schema, namespace is http://xmlns.jcp.org/xml/ns/javaee/

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee

http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

version="3.1">

Servlet 3.0

Java EE 6 XML schema, namespace is http://java.sun.com/xml/ns/javaee

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"

version="3.0">

Servlet 2.5

Java EE 5 XML schema, namespace is http://java.sun.com/xml/ns/javaee

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"

version="2.5">

Servlet 2.4

J2EE 1.4 XML schema, namespace is http://java.sun.com/xml/ns/j2ee

48304ba5e6f9fe08f3fa1abda7d326ab.png

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

version="2.4">

Servlet 2.4 Web Application

48304ba5e6f9fe08f3fa1abda7d326ab.png

Servlet 2.3

J2EE 1.3 DTDs schema. This web.xml file is too old, highly recommend you to upgrade it.

48304ba5e6f9fe08f3fa1abda7d326ab.png

/p>

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd" >

Servlet 2.3 Web Application

48304ba5e6f9fe08f3fa1abda7d326ab.png

web.xml头部声明到底是如何得来的????请往下看

相关文档说明下载:

http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html#7

下载文件:web-app_4_0.xsd 具体版本号自行决定本文以4.0版本为例打开xsd文件,我用的notepad++打开的。Web.xml的schema由文档了解

这是Servlet 4.0部署描述符的XML Schema。部署描述符必须在“WEB-INF/web.xml”

中命名Web应用程序的war文件。 所有Servlet部署描述符必须使用Java EE指示

Web应用程序架构命名空间:http://xmlns.jcp.org/xml/ns/javaee

并通过指示架构的版本使用如下所示的version元素:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="..."

version="4.0">

...

实例文档可能指示已发布的版本,使用Java EE的xsi:schemaLocation属性的模式具

有以下位置的命名空间:http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd

所以最终应写的头文件是:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee

http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

version="4.0">

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐