eclipse 由于 servlet 文件导致的 xml 错误找不到元素的声明,引用的文件包含错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17238986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xml error due to servlet file Cannot find the declaration of element , Referenced file contains errors
提问by Saurabh Gupta
i don't know why these error occured can someone explain me how to solve them -
我不知道为什么会发生这些错误有人可以解释我如何解决它们-
cvc-elt.1: Cannot find the declaration of element 'web_1:web-app'.
Referenced file contains errors (jar:file:/C:/Program Files/eclipse/plugins/org.eclipse.jst.standard.schemas_1.2.0.v201101142102.jar!/dtdsAndSchemas/web-app_2_5.xsd). For more information, right click on the message in the Problems View and select "Show Details..."
cvc-elt.1: Cannot find the declaration of element 'web_1:web-app'.
Referenced file contains errors (jar:file:/C:/Program Files/eclipse/plugins/org.eclipse.jst.standard.schemas_1.2.0.v201101142102.jar!/dtdsAndSchemas/web-app_2_5.xsd). For more information, right click on the message in the Problems View and select "Show Details..."
these are the two errors which i face and that because i added a servlet by mistake of which i intended to add a normal class file to my project .. then both these error starting to show even i delete the servlet file . this is my xml code (actually it is the basic code)- as i have not used a single servlet file untill yet , i only used jsp file.
这是我面临的两个错误,因为我错误地添加了一个 servlet,我打算将一个普通的类文件添加到我的项目中。然后,即使我删除了 servlet 文件,这两个错误也开始显示。这是我的 xml 代码(实际上它是基本代码)- 因为我还没有使用过单个 servlet 文件,所以我只使用了 jsp 文件。
still xml file -
仍然是 xml 文件 -
<?xml version="1.0" encoding="UTF-8"?>
<web_1:web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
xmlns:web_1="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID"
version="3.0">
<display-name>InitialD</display-name>
<web_1:welcome-file-list>
<web_1:welcome-file>index.html</web_1:welcome-file>
<web_1:welcome-file>index.htm</web_1:welcome-file>
<web_1:welcome-file>index.jsp</web_1:welcome-file>
<web_1:welcome-file>default.html</web_1:welcome-file>
<web_1:welcome-file>default.htm</web_1:welcome-file>
<web_1:welcome-file>default.jsp</web_1:welcome-file>
</web_1:welcome-file-list>
</web_1:web-app>
回答by subrat
Try this:
尝试这个:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
回答by shutear
As Mark and Saurabh said, it is workable to remove every instance of "web_1:" from your web.xml file. Meantime it is better to remove the reference to the schema "xmlns:web_1". A workable snippet based on Saurabh's problem as follow:
正如 Mark 和 Saurabh 所说,从 web.xml 文件中删除“web_1:”的每个实例是可行的。同时,最好删除对架构“xmlns:web_1”的引用。基于 Saurabh 问题的可行片段如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID"
version="3.0">
<display-name>InitialD</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
回答by Mark Thomas
Remove every instance of "web:" from your web.xml file.
从 web.xml 文件中删除“web:”的每个实例。