6

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)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286

2 Answers2

14

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    thanks, a added it. But now other error: According to TLD or attribute directive in tag file, attribute atribut_1 does not accept any expressions. After searching on Google, I understand that I must to change url,FROM <%@ taglib uri='http://java.sun.com/jstl/core' prefix='c'%> TO to <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%> BUT WHERE?? – WelcomeTo Nov 24 '11 at 16:55
  • That's a different problem. Ask a new question. Hint: ``. Read the linked tutorial. And no, JSTL has completely nothing to do with it. You're creating a **custom** JSP taglib. That's not the same as JSTL. It's just a **standard** JSP taglib. Forget JSTL at this point. To learn more about JSTL, check http://stackoverflow.com/tags/jstl/info – BalusC Nov 24 '11 at 16:58
  • thank you very much. I seted to true "rtexprvalue". Now: Unable to find setter method for attribute: atribut_1. I'll create new question – WelcomeTo Nov 24 '11 at 17:02
  • You're welcome. As to the new problem, well, that's self-explaining. Add a proper Javabean setter method `public void setAtribut_1(String atribut_1)`. Read the Javabeans spec for more detail (I'd also work on your [Java naming conventions](http://www.oracle.com/technetwork/java/codeconventions-135099.html#367); camelcase and so on). – BalusC Nov 24 '11 at 17:03
  • Yes, I added it. Also i add the tyoe of attribute, but it dont want to work. – WelcomeTo Nov 24 '11 at 17:17
2

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.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Mark
  • 1,884
  • 2
  • 25
  • 36