Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct .tld file header

Tags:

java

jsp

taglib

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)

like image 755
WelcomeTo Avatar asked Nov 24 '11 16:11

WelcomeTo


People also ask

What is .TLD file?

A tag library descriptor is an XML document that contains information about a library as a whole and about each tag contained in the library. TLDs are used by a web container to validate the tags and by JSP page development tools. Tag library descriptor file names must have the extension .

What is the use of .TLD file in struts?

The TLD file: The tag library descriptor (TLD) file is an XML file that contains meta-information about the tags within a library. Information such as the tag name, the attributes that are required, and the tag handler class name are all contained in this file and read in by the JSP container.

How create TLD file in JSP in Eclipse?

Just go for New->XML file and name the file as yourname. tld thats all !


2 Answers

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:

  • Java EE 5 tutorial - Tag library descriptors (to compare, check old J2EE 1.3 tutorial)
like image 69
BalusC Avatar answered Sep 21 '22 23:09

BalusC


Is your DOCTYPE incorrect? Try the following:

<?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/dtd/web-jsptaglibrary_1_2.dtd">

N.B. I would recommend the advice to update your definition to the Java EE 5 version if, indeed, you do want to use v2.1.

like image 45
Mark Avatar answered Sep 18 '22 23:09

Mark