gpt4 book ai didi

java - JSP 自定义标签 : missing DTD/XML Schema

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:06:28 24 4
gpt4 key购买 nike

我已经使用以下 TLD 编写了我的 JSP 自定义标记:

<?xml version="1.0" encoding="UTF-8"?>
<taglib
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.1">
<tlibversion>1.0</tlibversion>
<jspversion>2.1</jspversion>
...

现在 Eclipse Helios 提示“没有检测到文档的语法约束(DTD 或 XML 模式)。”

我知道如何禁用警告,而是想知道如何通过提供 DTD 或架构信息来解决问题。

顺便说一句,在上面的 XML 中我有:

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd"

但这似乎没有帮助。

更新 根据 Peter 的建议,我检查了我的 Window > Preferences > XML > XML Catalog,我发现以下内容可能适合:

Entry element:  Public
Location: dtdsAndSchemas/web-jsptaglibrary_1_2.dtd in jar file
usr/local/eclipse/plugins/org.eclipse.jst.standard.schemas_1.1.0.v201003031644.jar
URI: jar:file:/usr/local/eclipse/plugins/org
.eclipse.jst.standard.schemas_1.1.0.v201003031644.jar!/dtdsAndSchemas
/web-jsptaglibrary_1_2.dtd
Key type: Public ID
Key: -//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN

所以我尝试将以下内容添加到我的顶级域名中:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd">

现在我有以下错误:

在此行发现多个注释:

  • 必须为元素类型“taglib”声明属性“xsi:schemaLocation”。
  • 必须为元素类型“taglib”声明属性“version”。
  • 值为“http://java.sun.com/xml/ns/javaee”的属性“xmlns”的值必须为“http://java.sun.com/JSP/TagLibraryDescriptor”。

  • schema_reference.4:无法读取架构文档“web-jsptaglibrary_2_1.xsd”,因为

    1) 找不到文档;2)文档无法读取;3)文档的根元素不是。

  • 元素类型“taglib”的内容必须匹配“(tlib-version,jsp-version,short-name,uri?,display-name?,small-icon?,large-icon?,description? ,validator?,listener*,tag+)”。

  • 必须为元素类型“taglib”声明属性“xmlns:xsi”。

最佳答案

一个多月以来我都没有费心去研究这个问题,因为无论如何一切都在 Tomcat 中运行。最近我尝试了 GlassFish 和 JBoss。虽然 GlassFish 3.1.1 没有提示,但 JBoss 7.0 拒绝运行该应用程序,因为 tld 问题。与此同时,我还将 Eclipse Helios 更新为 Indigo。

我发现我同时使用了 DTD 和 Schema,这不太好。我放弃了 DTD,只保留了 Schema。我不得不重命名一些标签,例如 tlibversion 到 tlib-version,shortname 到 short-name,bodycontent 到 body-content,tagclass 到 tag-class,删除信息标签,我用 XML 注释替换它。我想这可能是规范的更新版本,因为在我遵循的示例中,它们的命名没有连字符。

之后一切正常:Eclipse 不再发出任何警告,JBoss 完美运行应用程序。这里的引用是工作的顶级域名:

<?xml version="1.0" encoding="UTF-8"?>
<taglib
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.1">
<tlib-version>1.0</tlib-version>
<short-name>StivloTags</short-name>
<uri>http://www.stefanolocati.it/</uri>

<!-- Example from http://www.stardeveloper.com/articles/display.html?article=2001081301&amp;page=1 -->
<tag>
<name>firstTag</name>
<tag-class>obliquid.tag.FirstTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>name</name>
<required>false</required>
</attribute>
</tag>

<!-- Truncate text after maxLength or 80 chars, adding "&amp;hellip;" if the the text was longer -->
<tag>
<name>ellipsis</name>
<tag-class>obliquid.tag.Ellipsis</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>maxLength</name>
<required>false</required>
</attribute>
</tag>

</taglib>

关于java - JSP 自定义标签 : missing DTD/XML Schema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6134139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com