JSP custom tags: missing DTD/XML Schema
I've written my JSP custom tag with the following TLD:
<?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>
...
Now Eclipse Helios complains that "No grammar constraints (DTD or XML schema) detected for the document."
I know how to disable the warning, I was instead wondering how to solve the problem by providing DTD or schema information.
By开发者_Go百科 the way in the above piece of XML I have:
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd"
but it doesn't seem to help.
UPDATE on Peter's suggestion I went to check in my Window > Preferences > XML > XML Catalog and I found the following that may fit:
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
So I tried to add the following to my 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">
Now I've the following errors:
Multiple annotations found at this line:
- Attribute "xsi:schemaLocation" must be declared for element type "taglib".
- Attribute "version" must be declared for element type "taglib".
Attribute "xmlns" with value "http://java.sun.com/xml/ns/javaee" must have a value of "http://java.sun.com/JSP/ TagLibraryDescriptor".
schema_reference.4: Failed to read schema document 'web-jsptaglibrary_2_1.xsd', because
1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .
The content of element type "taglib" must match "(tlib-version,jsp-version,short-name,uri?,display-name?,small-icon?,large-icon?,description?,validator?,listener*,tag+)".
- Attribute "xmlns:xsi" must be declared for element type "taglib".
I didn't bother looking at this problem for over a month, because anyway everything was working in Tomcat. Recently I tried GlassFish and JBoss. While GlassFish 3.1.1 didn't complain, JBoss 7.0 refused to run the application, because of tld problems. In the meantime I've also updated Eclipse Helios to Indigo.
I figured out that I was using DTD and Schema at the same time, which can't be good. I ditched the DTD and kept only the Schema. I had to rename a few tags, such as tlibversion to tlib-version, shortname to short-name, bodycontent to body-content, tagclass to tag-class, remove the info tag, which I substituted with XML comments. I guess it's probably a newer version of the specs, because in the example I followed they were named without hyphens.
After that everything worked: Eclipse didn't give any warning any more, JBoss ran the application perfectly. For reference here is the working 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&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 "&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>
If Eclipse doesn't automatically pick up the XSD from the library, you can always add it manually: Window > Preferences > XML > XML Catalog
In my case it was already present in the plugin section. It probably came with one of the Eclipse Java EE plugins.
its
java.sun.com/dtd/web-jsptaglibrary_1_2.dtd
not
http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd
go to the second link you will see.
faced the same problem . the file itself said that the location is changed.
精彩评论