Correct .tld file header

MyTitle picture MyTitle · Nov 24, 2011 · Viewed 8.8k times · Source

I want to create custom tag, but i get "XML parsing error" on JSPVersion line. I check my JSP version, is exactly 2.1. I think error in links.

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

<jsp-version>2.1</jsp-version>

Can anyone help me? Thanks

UPD/ ERROR MESSAGE: org.apache.jasper.JasperException: Unable to initialize TldLocationsCache: org.apache.jasper.JasperException: XML parsing error on file /WEB-INF/tlds/tag.tld: (line 11, col 2)

Answer

BalusC picture BalusC · Nov 24, 2011

You're using a old JSP 1.2 tag library declaration in flavor of a DTD. You need to remove it (and also the <jsp-version>) and use the new JSP 2.1 XSD declaration:

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

    <!-- Taglib config here -->
</taglib>

Ensure that you're reading the proper books/tutorials for JSP 2.1, not JSP 1.2.

See also: