element XXX is not allowed here的错误。网上不少说重启idea或者Tomcat的jar包配置的,真是但愿本身试一下再转帖啊,几篇错误的能抄的处处都是,害人害己啊。html
一、注意比对web.xml的头文件格式是否正确。java
<web-app xmlns="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"> </web-app>
<web-app xmlns="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"> </web-app>
<web-app xmlns="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"> </web-app>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 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"> <display-name>Servlet 2.4 Web Application</display-name> </web-app>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Servlet 2.3 Web Application</display-name> </web-app>
web.xml头部声明究竟是如何得来的????请往下看web
相关文档说明下载:架构
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html#7oracle
下载文件:web-app_4_0.xsd 具体版本号自行决定本文以4.0版本为例打开xsd文件,我用的notepad++打开的。Web.xml的schema由文档了解app
这是Servlet 4.0部署描述符的XML Schema。部署描述符必须在“WEB-INF/web.xml”
中命名Web应用程序的war文件。 全部Servlet部署描述符必须使用Java EE指示
Web应用程序架构命名空间:http://xmlns.jcp.org/xml/ns/javaee
并经过指示架构的版本使用以下所示的version元素:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="..."
version="4.0">
...
</web-app>
实例文档可能指示已发布的版本,使用Java EE的xsi:schemaLocation属性的模式具
有如下位置的命名空间:http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd
因此最终应写的头文件是:ide
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="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_4_0.xsd"
version="4.0">
</web-app>idea