【发布时间】:2011-09-02 07:28:37
【问题描述】:
我使用以下 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
所以我尝试将以下内容添加到我的 tld:
<?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”。
【问题讨论】:
-
我的第一个问题是,您是否在为 Java EE 开发人员使用 Eclipse?
-
是的,我下载了 Java EE 的包。