JSP自定义标记:缺少DTD/XML模式

sti*_*vlo 7 java jsp-tags

我用以下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>
  ...
Run Code Online (Sandbox Code Playgroud)

现在Eclipse Helios抱怨"没有检测到文档的语法约束(DTD或XML模式)."

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

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

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd"
Run Code Online (Sandbox Code Playgroud)

但它似乎没有帮助.

更新 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
Run Code Online (Sandbox Code Playgroud)

所以我试着将以下内容添加到我的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">
Run Code Online (Sandbox Code Playgroud)

现在我有以下错误:

在此行找到多个注释:

  • 必须为元素类型"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*,标签+)".

  • 必须为元素类型"taglib"声明属性"xmlns:xsi".

sti*_*vlo 14

我花了一个多月的时间没有看这个问题,因为无论如何一切都在Tomcat中运行.最近我尝试了GlassFish和JBoss.虽然GlassFish 3.1.1没有抱怨,但由于tld问题,JBoss 7.0拒绝运行该应用程序.与此同时,我还将Eclipse Helios更新为Indigo.

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

之后一切正常:Eclipse不再发出任何警告,JBoss完美地运行了应用程序.这里是参考工作tld:

<?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>
Run Code Online (Sandbox Code Playgroud)


Pet*_*ter 2

如果 Eclipse 没有自动从库中获取 XSD,您始终可以手动添加它:Window > Preferences > XML > XML Catalog

就我而言,它已经存在于插件部分中。它可能附带 Eclipse Java EE 插件之一。