JSTL Custom Tags
Hello,
I'm new to JSTL and am trying to write a custom tag. I am using Tomcat. I wrote a java class that I put in WEB-INF\classes, a tld that I put in WEB-INF\tags and the jsp page that uses the custom tag. When I try to run the page in tomcat I get the following error:
org.apache.jasper.JasperException: /book.jsp(2,0) No tag "ifWeekday" defined in tag library imported with prefix "book"
I would be very grateful for any help.
Thanks in advance,
Ger
[490 byte] By [
clojinteda] at [2007-10-2 15:37:36]

Just to point out, custom tags aren't a JSTL thing, they're a JSP thing...That being said...
You'll need to post your tld file, as well as the taglib directive you put at the top of your page. This would help us to figure out your problem(s).
Also note that you're going to need to package that class. You can't have it in the classes root. If you don't know how to package classes, also let us know that...
Hello,
My tld file is as follows:
<?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">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>book</short-name>
<uri>http://jstlbook.com/tld/weekday.tld</uri>
<tag>
<name>ifWeekday</name>
<tag-class>com.jstlbook.examples.WeekdayTag</tag-class>
</tag>
</taglib>
As you can see the class is in the com.jstlbook.examples package which I put in the classes folder.
My taglib directive is as follows:
<%@ taglib prefix="book" tagdir="/WEB-INF/tags/weekday.tld"%>
Thanks very much for getting back to me. If you need anymore information let me know.
Ger
The uri you have referenced in your taglib declaration is not valid. If I enter it in a browser, I cannot see it. That needs to be changed. I assume that you are placing it here:
/WEB-INF/tags/weekday.tld
Then that should be your uri value.
Also note in your taglib directive, replace tagdir="/WEB-INF/tags/weekday.tld" with uri="/WEB-INF/tags/weekday.tld". It will not match the uri listed in the tld and if that's where it is, it should work.
Post back to we know how you're making out.
>The uri you have referenced in your taglib declaration is not valid. If I
>enter it in a browser, I cannot see it.
What does that have to do with anything?
The URI in the taglib is NOT a reference out to the internet to download something from. It is a URI purely internal to the server.
I could use the following in the tld:
<uri>http://i.am.the.greatest</uri>
and then in the jsp page:
<%@ taglib prefix="book" tagdir="http://i.am.the.greatest"%>
Check out the JSP2.0 spec section 7.3.4
I made the suggested changes and am now getting the following error:
org.apache.jasper.JasperException: Unable to initialize TldLocationsCache: null
In case something needs to be set in the web.xml file mine reads as follows:
<web-app>
<taglib>
<taglib-location>
/WEB-INF/tags/weekday.tld
</taglib-location>
</taglib>
</web-app>
In relation to the uri in the tld can the uri be a path like /WEB-INF/tags/weekday.tld or does it have to be in the http://www.something.com format.
Thanks again for the help,
Ger
You need to define a taglib uri in web.xml
1.
<taglib>
<taglib-uri>/tags/weekdayTags</taglib-uri>
<taglib-location>/WEB-INF/tags/weekday.tld</taglib-location>
</taglib>
Note if you are using servlet 2.4, this should be inside a <jsp-config> element.
2. Next you need to have a tld file called weekday.tld in the WEB-INF/tags directory (I guess you already have this setup).
3. And finally in your jsp, use the uri defined in your web.xml (note, as evnafets pointed out, it neednt be of http://....format)
<%@ taglib uri=">/tags/weekdayTags" prefix="weekday" %>
<weekday:someTag .......>
ram.
Brilliant! That was the final piece alright. Thanks very much to all for your help.Ger