This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes About resolving URIs to TLD file locations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "About resolving URIs to TLD file locations" Watch "About resolving URIs to TLD file locations" New topic
Author

About resolving URIs to TLD file locations

Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
Hello everyone!

I am a bit confused about resolving URIs in the JSP file to TLD file locations. Say, there is a test.jsp file which is located in the <web application root directory>\jsp\test.jsp. In this file, a taglib directive declared as <%@ taglib prefix="hello" uri="sampleLib.tld" %>. I think when the JSP enginee encounters the directive, it does the following two things,

(1) First, it checks the taglib map. If there is an explicit mapping in web.xml file, which has defined something as,
<taglib-uri>sampleLib.tld</taglib-uri>
<taglib-location>realLib.tld</taglib-location>
then the container will associate this URI to the actual TLD file-realLib.tld which is located in <web application root directory>\WEB-INF\realLib.tld.
In other case, if the <taglib-location>element defines as <taglib-location>/realLib.tld</taglib-location>, then the container will find the real TLD file-realLib.tld in the <web application root directory>realLib.tld.

(2) Second, if there is not any matching in the taglib map, the container will expect to find the real TLD file-sampleLib.tld in the same directory as the current test.jsp file, which directory is <web application root directory>\jsp\sampleLib.tld.

I want to know whether the workflow mentioned above is correct and the TLD file locations which I use bold characters are right in every case.

I also find if a TLD file packaged in a JAR file, a lot of examples use absolute URI to define the TLD file's <uri> element. Do we have to use absolute URI instead of relative URI? I think both URIs can be used in such situation. Is it right?

Thanks in advance!
Regards, Ailsa Cape
[ February 12, 2006: Message edited by: Ailsa Cape ]
muthu kumaran
Ranch Hand

Joined: Oct 26, 2004
Posts: 56
Hi Ailsa ,

The First thing you should note is " The URI need not point to the location where the TLD is stored. It is present only to resolve namespace issues."

Coming to your points on the TLD mapping

Point 1 is perfect( if a taglib element is present in the DD then the container first looks at it to find the TLD file)

Coming to the second point


if there is not any matching in the taglib map, the container will expect to find the real TLD file-sampleLib.tld in the same directory as the current test.jsp file, which directory is <web application root directory>\jsp\sampleLib.tld



This is not correct . The container expects to find the TLD files only
a)Directly under WEB-INF or any subdirectory in WEB-INF
b) If TLD is packaged along with the jar file , then the container expects
the TLD to be present under META-INF or any subdirectory of META-INF
in the jar file under WEB-INF/lib/

If these searches fail, then the container wud try to resolve the URI ( this is the last option the container uses to locate the TLD)
Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
Hi muthu,

Thank you a lot! According to your instructions, I think my previous second step should be divided into two parts:
a) If the TLD file isn't in a JAR file, the container expects to find it directly under WEB-INF or any subdirectory in WEB-INF.
b) Just as you said, the container searches the implicit taglib map:
b) If TLD is packaged along with the jar file , then the container expects
the TLD to be present under META-INF or any subdirectory of META-INF
in the jar file under WEB-INF/lib/

,and there should be added the third step which is the container will search the JSP file's current directory to find the real TLD file location.
Is it right? Or is this third step equal to your describing?
If these searches fail, then the container wud try to resolve the URI ( this is the last option the container uses to locate the TLD)
Do I understand correctly?

Thanks again!
Best Regards, Ailsa Cape
 
Consider Paul's rocket mass heater.
 
subject: About resolving URIs to TLD file locations
 
Similar Threads
URI question
Tag Library and Tag Library Descriptor
can somebody explain this with eg
no need for <taglib> tag in the web.xml
taglib-location value in web.xml