*
The moose likes JSP and the fly likes Tag Library Decriptor Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Tag Library Decriptor Problem" Watch "Tag Library Decriptor Problem" New topic
Author

Tag Library Decriptor Problem

Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
I am brand new at trying tag library development and am trying to build a simple custom tag using Netbeans 4.1 and I get the following error when running the JSP and when inside the Netbeans IDE:

Error:
File "/WEB-INF/JavascriptExampleTag.tld" not found

Note, the tld is in the WEB-INF directory and the tag handler is in directory com.jspinsider.jspkit.javascript

Here is my tld, with web-xml and JSP taglib declaration to follow:

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

<tlib-version>1.0</tlib-version>
<short-name>JavaScriptExampleTag</short-name>
<uri>http://linux:8084/jspkit/javascript</uri>
<tag>
<name>message</name> <tag-class>com.jspinsider.jspkit.javascript.JavaScriptExampleTag</tag-class> <body-content>JSP</body-content>
</tag>

</taglib>

web.xml file:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>

<taglib>
<taglib-uri>http://linux:8084/jspkit/javascript</taglib-uri>
<taglib-location>/WEB-INF/JavascriptExampleTag.tld</taglib-location>
</taglib>

</web-app>

JSP Declaration:
<%@taglib uri="http://linux:8084/jspkit/javascript" prefix="JavaScript"%>

JSP Attempt to use tag:
<JavaScript:message>
Simple Alert
</JavaScript:message>

This simple tag is coded and has the same deirectory structure exactly as depicted in Wrox Professional JSP 2nd Edition tutorial. I have been at this four many hours. Any help greatly appreciated. Thanks.
[ January 19, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Remove the taglib element from the web.xml. It is superfluous. The container should pick up any tld files place under the WEB-INF folder automatically by URI.

Also, I'd rethink your choice of URI. I'm pretty sure that you do not own the domain "linux". You should be using a domain that you own to ensure that there is never a URI name collision with other tld URIs.

Btw, what JSP container does Netbeans 4.1 employ? Is it up to date?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
As soon as taglib element was removed from web.xml the error went away and the tag works. I used linux inthe URI because for some reason my localhost machine name defaults to linux so for now I changed it to localhost. Must read more about URI.

Netbeans 4.1 supports J2ee 1.3 and 1.4 The container used depends on the target servers that you configure Netbeans to use. In my case they are Tomcat 5.5.7 and Sun Java System Application Server 8.1

Thanks very much for your help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Must read more about URI.


URIs are not URLs. They are identifiers not llocators. As such, they don't point to anything. They are just used as a string that identifies something. So you don't need to use the name of your machine, or localhost, or anything else that really resolves to anything real on the net.

URIs could have been just any random string, but the convention chosen (hotly debated in some circles) was to use domain names in the URIs to avoid naming collisions.

For example, I own bibeault.org. So I used that domain name in the URI for the tag library I created for my latest JavaRanch Journal article (semi-shameless plug). Because no one else can own bibeault.org, it should never be used in anyone else's URI and so no one should ever try to use the same URI for their own library.

If you own a domain (all self-respecting web developers should), you should use it in your URIs. If not, make up something plausible that is unlikely to collide with someone else's.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Netbeans 4.1 supports J2ee 1.3 and 1.4 The container used depends on the target servers that you configure Netbeans to use. In my case they are Tomcat 5.5.7 and Sun Java System Application Server 8.1


If you are using Tomcat 5 you should consider updating your web.xml to declare your web app as a Servlets 2.4 web app (rather than 2.3 as you are doing now). Otherwise, you are hobbling Tomcat into compatibility mode and will not be able to use the full range of features.

The JSP FAQ has info on how to declare the web.xml appropriately.
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
Is it ok to declare the uri as the place where the tag handler classes reside if not using the domain? This is for local development and learing. If domain is available as in production I would use the domain.

For example I currently am using <uri>/WEB-INF/taghandlers</uri> in the TLD and the JSP.

I think I understand what your are saying about the URI because the only requirement that the IDE seems to enforce is that the TLD URI declaration and JSP URI declaration are the same.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

If the tag library is never going to leave your computer, you can really name it anything you want as long as you are careful not to accidentally name it the same as someone else's library you are likely to use.

Even so, I'd follow the convention of using URIs that look like URIs, not like file locations. That's part of sticking to conventions so no one ends up confused.

So I'd name it something like:

http://stu.higgs.mytags/somenameforyourlibrary

which looks like a real URI.
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
Sounds good, thank you. Another situation comes up now when deploying the tag via WAR file.

When I deployed the Web-Module to another server running Tomcat 5.0 I get the following error related to the URI declaration:

File "/WEB-INF/taghandlers" not found
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Originally posted by Stu Higgs:

File "/WEB-INF/taghandlers" not found


Where are you referencng this folder from?
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
Where are you referencng this folder from?


Just declarations in JSP taglib declaration and TLD taglib declaration, but that is the location of the tag handler class. All is working on the local machine. Maybe problem with deployment descriptor? I know little about deployment descriptors.

JSP:
<%@taglib uri="/WEB-INF/taghandlers" prefix="js"%>

TLD:
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd" version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>tags</short-name>
<uri>/WEB-INF/taghandlers</uri>
<tag>
<name>javascriptgenerator</name>
<tag-class>taghandlers.JavaScriptGeneratorTag</tag-class>
<body-content>JSP</body-content>
</tag>
</taglib>
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
Remove the taglib element from the web.xml. It is superfluous.


I'm a little stumped but am researching the current problem I'm having with deploying the web application with the tag library. I thought perhaps putting the <taglib></taglib> in web.xml might fix the problem with deploying, but I do not see any taglib element under the web-app Element Structure in the 2.4 specification, and The IDE does not like the presence of the <taglib> in web.xml In some older reference material that I have read it is stated that web.xml would be the place to do this.... Obviosuly I am missing something here...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

First thing first. Rework your URI to look like a URI as we discussed. I'm doing some research, but meantime that's the first thing to do.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

As I suspected, if the uri of the taglib directive does not follow the accepted pattern for a URI, it is assumed to be a file path relative to the context root.

So I suspect that fixing your URI will fix your problem.
[ January 19, 2006: Message edited by: Bear Bibeault ]
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
Thanks, I will try that. I also read a little more inthe 2.4 specification and found that the <taglib> element should be declared in web.xml using <jsp-config> as the parent to the <taglib> After adding the following to web.xml I was able to successfully deploy and run the application on another server.

<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/taghandlers</taglib-uri>
<taglib-location>/WEB-INF/tags.tld</taglib-location>
</taglib>
</jsp-config>

Now I will also change the taglib directive to conform to the accepted pattern for URI so that it is not assumed to be a file path relative to the context root and see what happens. Thanks.
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
I tried using the URI as discussed in the above posts. Maybe I did something wrong because it is not working. I'll keep experimenting with it. Here is the error message:

This absolute uri (http://stu.higgs.mytags/mytaghandlers) cannot be resolved in either web.xml or the jar files deployed with this application


Here are the tld and jsp for reference
tld:
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd" version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>tags</short-name>
<!--<uri>/WEB-INF/taghandlers</uri>-->
<uri>http://stu.higgs.mytags/mytaghandlers</uri>

<tag>
<name>javascriptgenerator</name>
<tag-class>taghandlers.JavaScriptGeneratorTag</tag-class>
<body-content>JSP</body-content>
</tag>

</taglib>

JSP:
<%@taglib uri="http://stu.higgs.mytags/mytaghandlers" prefix="tag"%>

Is there any reason that I shoud absolutely not use the web.xml?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Where did you place the tld file? It should be in the folder hierarchy under WEB-INF, but not in either of WEB-INF/classes or WEB-INF/lib.

The URI in the tld file matching the URI in the taglib declaration should be sufficient for Tomcat to find and hook up the taglib (assuming everything is set up properly, of course).

The elements in the web.xml are not necessary in this instance so you shouldn't use them. It's just something else that would need to be kept in synch and is a potential for problems. The web.xml element is useful only for cases where you need to override the URI that's in the tld for some reason. You don't have one.
[ January 19, 2006: Message edited by: Bear Bibeault ]
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
The tld is in the WEB-INF with no sub directory. TLD declaration matches JSP declaration. I have tried several variations forming the URI below is the latest. As far as I can see everything is set up correctly. No problems running locally using URI with no config in web.xml

Same error when running after deploy:
This absolute uri (http://localhost/taghandlers) cannot be resolved in either web.xml or the jar files deployed with this application.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

OK, using Tomcat 5.0.25, I:

1) took your tld file and dropped it into WEB-INF.
2) Created a JSP that contained your taglib directive
3) Restarted the web app
4) Hit the page

Result: no problem.

You did restart the app after adding the tld file to WEB-INF, right?

This absolute uri (http://localhost/taghandlers)


This is not the URI that's in your examples. Are you sure everything is set up consistently?
[ January 20, 2006: Message edited by: Bear Bibeault ]
Stu Higgs
Ranch Hand

Joined: Jan 01, 2006
Posts: 74
I've been trying different variations on the URI, even though it doesn't really map to anything. Thats why your seeing different URI throughout the posts.

After deploying to the other server via WAR file I restarted Tomcat. I'm pretty sure everything is set up correctly. There are no problems running it on the local machine using URI alone with no web.xml mapping.

I'll keep trying to figure it out. For now I'm happy that I can proceed learning how to work with Tag Libraries atleast on the local machine using just the URI and no web.xml

When I do get the deployed version to work using just the URI and no web.xml I will return and update this thread. Thanks again for your help with everything. Much appreciated.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

OK, best of luck! I can think of no reason why something that works locally should not work on another server if the set up is the same.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tag Library Decriptor Problem
 
Similar Threads
problem in displaying dropdown menu items in jsp with jstl
Problems making Struts/JSTL 1.2 site work with JSTL 2.0
tld question
Compiling JSP+ Tag in Tomcat 4.0.3/Forte IDE 2.0