• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possible location of TLDs

 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Ranchers!

I am reading the B&K HF book and I'm in chapter 11, question 2, pp. 643, which is:

Where do you store Tag Library Descriptors (TLDs), in a web application? (Choose all that apply.)

A. Only in /WEB-INF/lib.
B. Only in /WEB-INF/classes.
C. In the /META-INF directory of a JAR file inside /WEB-INF/lib
D. At the application’s top-level directory.
E. In /WEB-INF or a sub-directory thereof.


The question itself is fine, but the answer is not clear for me:

The container will not automatically discover TLDs if they are in /WEB-INF/classes or /WEB-INF/lib.


I take the Servlet 3.0 final spec and read:


The following order of precedence applies (from highest to lowest) when building the taglib map (see the following sections for details):

1. If the container is Java EE platform compliant, the Map Entries for the tag libraries that are part of the Java EE platform. This currently includes the JavaServer Pages Standard Tag Library libraries and the JavaServer Faces libraries.
2. Taglib Map in web.xml,
3. Implicit Map Entries from TLDs,
  - TLDs in JAR files in WEB-INF/lib,
  - TLDs under WEB-INF,
4. Implicit Map Entries from the Container.


For me - "under WEB-INF" means also in WEB-INF/lib and WEB-INF/classes. I've tested it (also on Tomcat 6.x, so with Servlets 2.4) and it does find TLDs under those directories without a gasp...

So I think you understand what is the question about :-)

Cheers!
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pedro,

The container will not automatically discover TLDs if they are in /WEB-INF/classes or /WEB-INF/lib.

There is a difference between explicit mapping and implicit mapping:
  • explicit mapping: the taglib directive in a JSP-file has an URI that corresponds with a <taglib-uri> in the <taglib> element of the web.xml. The location of the TLD file is found in the <taglib-location> element.
  • implicit mapping: : the taglib directive in a JSP-file has an URI that doesn't match any <taglib-uri> in the <taglib> element of the web.xml. The JSP container gets the location by searching the subdirectories of /WEB-INF and the jar's in /WEB-INF/lib for a TLD file with a matching URI.

  • The container will only find the TLD if the TLD has a <uri> element (which is optional and not required with the explicit mapping)

    Regards,
    Frits
     
    Piotr Nowicki
    Ranch Hand
    Posts: 611
    1
    IntelliJ IDE Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Frits for your time and pointing to the explicitely/implicitely TLDs mapping part!

    Ok, I think that I understand the difference between implicit and explicit mappings.

    If I do not have an <uri> element in my TLD - I need to explicitely map my TLD to the URI by adding the following part



    to the web.xml, right?

    But if I have the <uri> element in TLD, than I do not need the above part in web.xml. The container will find the file automatically (implicitely add the <taglib>... part or in other words - will map my file to the URI given in TLD) if it's under /WEB-INF/ directory, right?

    So, we go back to the original HF statement, which in my opinion is false.

    The container WILL automatically discover TLDs if they are in a subdirectory of /WEB-INF/ - even if it's classes or lib subdirectory.

    What do you think Frits?
     
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Saloon Keeper
    Pie
    Posts: 2536
    113
    Android Chrome Eclipse IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    But if I have the <uri> element in TLD, than I do not need the above part in web.xml. The container will find the file automatically (implicitely add the <taglib>... part or in other words - will map my file to the URI given in TLD) if it's under /WEB-INF/ directory, right?

    Yes it will search and discover all TLDs in /WEB-INF and all the subdirectories of /WEB-INF

    So, we go back to the original HF statement, which in my opinion is false.
    The container WILL automatically discover TLDs if they are in a subdirectory of /WEB-INF/ - even if it's classes or lib subdirectory.

    Ok, I now see what you mean. I only read the answer (was that statement given as an answer to option A and B? Or E?).
    Yes, that statement is not correct

    Regards,
    Frits
     
    Piotr Nowicki
    Ranch Hand
    Posts: 611
    1
    IntelliJ IDE Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This statement seems to be not related with any particular answer. The right answers are C and E which I agree with - I just was confused when I read this part talking about some magic features of the /WEB-INF/classes and /WEB-INF/lib :-)

    Thanks Frits, I think this topic can be treat as solved right now.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic