在 Eclipse 中找出 web.xml 错误

发布于 2024-09-13 02:51:05 字数 454 浏览 2 评论 0原文

当 Eclipse 检测到无效的 XML 文档(在我的例子中是 web.xml 文件)时,它会转储 DTD 的内容模型并告诉我该元素无效。这毫无帮助,因为它最终告诉我:

元素类型“web-app”的内容必须匹配“(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*, servlet 映射*、会话配置?、mime 映射*、欢迎文件列表?、错误页面*、taglib*、资源环境引用*、资源引用*、安全约束*、登录配置?,安全角色*,env-entry*,ejb-ref*,ejb-local-ref*)"。

在 900 行的 web.xml 文件中,错误不容易被发现。

如何找出导致文档无效的第一个元素?

When Eclipse detects an invalid XML document, in my case a web.xml file, it dumps the content model of the DTD and tells me that the element is invalid. This is quite unhelpful, since it ends up telling me that:

The content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)".

In a 900-line web.xml file, the error is not easy to find.

How can I single out the first element which causes the document to be invalid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨洒年华 2024-09-20 02:51:05

我知道这是一个老问题,但对我来说,它最终是 web.xml 选项的顺序。如果您查看错误消息,您的元素需要按照错误中列出的确切顺序排列。例如:

<web-app>

<display-name>LBSPing!</display-name>

<context-param>
    ...
</context-param>

<listener>
    ...
</listener>

<servlet>
    ...
</servlet>

<servlet-mapping>
    ...
</servlet-mapping>

</web-app>

对我来说,我的上下文参数位于我的 servlet 和侦听器节点之后,这导致了我的问题。

I know this is an old question, but for me it ended up being the order of the web.xml options. If you look at the error message, your elements need to be in the exact order listed in the error. For instance:

<web-app>

<display-name>LBSPing!</display-name>

<context-param>
    ...
</context-param>

<listener>
    ...
</listener>

<servlet>
    ...
</servlet>

<servlet-mapping>
    ...
</servlet-mapping>

</web-app>

For me, my context-params were after my servlet and listener nodes, which was causing my issue.

瑶笙 2024-09-20 02:51:05

我将创建 web.xml 的副本并将内容切成两半(确保其保持格式良好),直到找到该元素。之后,添加复制文件的其余部分。

I would create a copy of the web.xml and cut the content in halves, (ensuring it stays well-formed) until I found the element. After that you add the remaining parts of your copied file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文