Well, I'm trying to contain common tag libraries in a single, common, easily 
deployable space so I only have to deploy them once for all apps, and not into 
every app in existence (though there are arguments to be made for each app 
having its own independent stuff, even if it is the exact same stuff).  

That path <taglib-location>/lib/tld/c.tld</taglib-location> works just fine 
with the JSTL tags, but not my custom tags.  It is easy enough to put my TLD 
declaration in the META-INF/web.xml.  It is now becoming a matter of "wtf"....

However, my Tomcat is not responding as you suggest.  The Tag libs are not 
relative to the JSP, but to the context root, always.  That is, at my context 
root, I have my JSP:

===================================

<%@ page contentType="text/html; charset=iso-8859-1" language="java" 
errorPage="/error.jsp"%>
<%@ taglib uri="http://java.sun.com/jstl/core"; prefix="c"%>
<%@ taglib uri="jmorganTags" prefix="jm"%>

<c:set var="coreVar" scope="page" value="King Kong"/>
<jm:setIf var="testVar" test="${param.p == null}" trueValue="null" 
falseValue="${param.p}"scope="page"/>

<html>
<body>
<p>Hello from mm/test.jsp</p>
<img src="/images/test.gif"/>
<p>JM Taglib Var Set: ${testVar}</p>
<p>Core Taglib Var Set: ${coreVar}</p>
</body>
</html>

===================================

And... under {context-root}/secondLevel, I have another, almost identical JSP 
(just different text to ID the difference):

===================================

<%@ page contentType="text/html; charset=iso-8859-1" language="java" 
errorPage="/error.jsp"%>
<%@ taglib uri="http://java.sun.com/jstl/core"; prefix="c"%>
<%@ taglib uri="jmorganTags" prefix="jm"%>

<c:set var="coreVar" scope="page" value="Second Level - King Kong"/>
<jm:setIf var="testVar" test="${param.p == null}" trueValue="Second Level - 
null" falseValue="${param.p}"scope="page"/>

<html>
<body>
<p>Hello from mm/test.jsp</p>
<img src="/images/test.gif"/>
<p>JM Taglib Var Set: ${testVar}</p>
<p>Core Taglib Var Set: ${coreVar}</p>
</body>
</html>

===================================

Note the taglib references are identical between the two.  

The CORE jstl tags are (now) referenced in my {catalinahome}/conf/web.xml as:

===================================
    <taglib>
      <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
      <taglib-location>/lib/tld/c.tld</taglib-location>
    </taglib>
===================================

And my custom tags are in my {contextRoot}/META-INF/web.xml as:

===================================
    <taglib>
      <taglib-uri>customTags</taglib-uri>
      <taglib-location>/../../lib/tld/custom.tld</taglib-location>
    </taglib>
===================================

And BOTH work for BOTH the JSPs regardless of their location relative to the 
context root.  However, if I simply move the custom tag reference from the 
{contextRoot}/META-INF/web.xml into the {catalinahome}/conf/web.xml, the custom 
tags stop working.  It is as if JSTL is built into Tomcat...  Because the JSTL 
stuff seems to be able to be referenced either way; by my ugly relative path 
and by the cleaner "/lib/tld/c.tld" version.  However, my custom tags ONLY work 
when referenced within the {contextRoot}/META-INF/web.xml with 
"/../../lib/tld/custom.tld"




-----Original Message-----
From: Christopher Schultz [mailto:ch...@christopherschultz.net] 
Sent: Monday, October 26, 2009 10:40 AM
To: Tomcat Users List
Subject: Re: File "/customTagLibs" not found

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joseph,

On 10/23/2009 8:02 AM, Joseph Morgan wrote:
> <taglib-location>../../../lib/tld/customTagLibs.tld</taglib-location>

Yikes! Why not use a context-relative path like:

<taglib-location>/lib/tld/customTagLibs.tld</taglib-location>

This assumes that "/lib" is in the root of your webapp. Perhaps all the
".."s are getting things confused.

I try never to use ".." in any path. Most paths starting with "/" are
guaranteed to be relative to the context root by either the servlet or
JSP specifications. This particular one is covered in section 1.2.1 of
the JSP 2.0 spec.

> Here is the interesting thing.  If I remove just the custom tag lib
> entry from tomcat's conf/web.xml and put it in any apps WEB-INF/web.xml,
> it works!

Aah, I think relative references are the problem here. The path is
relative to the JSP itself, so if you have JSPs are multiple levels, the
".."s will screw things up. If you are looking at /index.jsp, then the
tab library is expected to be in "[webapp root]/../../../lib/....."
which is almost certainly incorrect.

> That is, all my other "common" tag lib declarations are
> still in conf/web.xml, but the custom tag lib declaration is all by
> itself within the WEB-INF/web.xml file.  Everything else is exactly in
> the same place, under "{catalinahome}/lib"....

Oh, you need these files in catalina's lib directory? Why not deploy
them alongside your webapp (or each webapp that needs them)?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrlwrgACgkQ9CaO5/Lv0PAvwACfb+3wYyjHhcCUfnC4sTZv3GAW
A4YAoJFzgKlyxSFa7mjIOMvIzX+ujiMz
=Nlaj
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to