【问题标题】:xml error due to servlet file Cannot find the declaration of element , Referenced file contains errors由于 servlet 文件导致的 xml 错误找不到元素的声明,引用的文件包含错误
【发布时间】:2013-06-21 15:28:23
【问题描述】:

我不知道为什么会出现这些错误,谁能解释我如何解决它们 -

  1. cvc-elt.1: Cannot find the declaration of element 'web_1:web-app'.
  2. 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..."

这是我面临的两个错误,因为我错误地添加了一个 servlet,我打算将一个普通的类文件添加到我的项目中.. 然后即使我删除了 servlet 文件,这两个错误也开始显示。 这是我的 xml 代码(实际上是基本代码)- 因为我还没有使用过单个 servlet 文件,所以我只使用了 jsp 文件。

仍然是 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>

【问题讨论】:

  • 如果您需要任何其他文件..请告诉

标签: java eclipse apache jsp servlet-3.0


【解决方案1】:

试试这个:

<?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">

【讨论】:

  • 请注意,XML/HTML 标记不会出现在答案中,除非它们被反引号 (`) 转义或整行缩进四个空格。跨度>
  • 这行得通。就我而言,问题是我有 2.5 版,当我下载一些新的 eclipse 服务器包时出现了错误。但是你的 sn-p 修复了它,因为我们的截图是 3.0 版。
【解决方案2】:

正如 Mark 和 Saurabh 所说,从 web.xml 文件中删除“web_1:”的每个实例是可行的。同时最好删除对模式“xmlns:web_1”的引用。基于 Saurabh 问题的可行 sn-p 如下:

<?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>

【讨论】:

    【解决方案3】:

    从您的 web.xml 文件中删除“web:”的每个实例。

    【讨论】:

    • 你的意思是 xml 文件中的 web_1
    • 谢谢你的回答..它对我有用..因为我不能投票给你(对此感到抱歉)但现在它工作正常..再次感谢你..
    猜你喜欢
    • 2019-02-25
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多