• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

could not understand tagdir attribute of taglib directive ?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the hfsj book says that

1. the container searches for tag files in WEB-INF/tags or subdirectory or META-INF/tags or subdirectory(inside jar file in WEB-INF/lib).

2. if the tag files is deployed in jar file we need to specify that in tld like <tag-file><name>Header</name><path>/META-INF/tags/Header.tag</path></tag-file>

suppose my tag file is in WEB-INF/tags/one/two/three/Header.tag

now container is supposed to find this tag file automatically since it is container specified location. right. if this is the case then WHY we need to specify the full path to tag file in taglib directive like this:

<%@taglib prefix="myadvice" tagdir="/WEB-INF/tags/one/two/three" %>

cant container prepare a map or something like it do with tld files ?
 
Enthuware Software Support
Posts: 4575
45
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can. tagdir just tells the container that you are going to use the prefix specified by the prefix attribute for all the tags installed in the directory given by tagdir attribute in that JSP page.

It is not like you absolutely have to use tagdir attribute. If you know the uri value (you can look it up in the tld file), you can use the uri attribute instead of tagdir.
 
Creator of Enthuware JWS+ V6
Posts: 3395
312
Android Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes and it also makes it quite flexible because I can now have 2 tags with the same name (e.g. mytag.tag) but attach it to another prefix:



Regards,
Frits
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul and Frits. i understand that we can use uri also in place of tagdir. also fritz i got your point that prefixes act as namespaces and we can use same name for our tags/tagfile. but still i have a doubt.

if i use uri in place of tagdir then in the TLD file i will have something like this. assume that tag file is deployed in jar file at /META-INF/tags


<uri>/myuri</uri>
<tag-file>
<name>Header</name>
<path>/META-INF/tags/Header.tag </path>


</tag-file>

now suppose in jsp i use the following

<%@taglib prefix="myadvice" uri="/myuri" %>

<myadvice:Header />


now when the jsp engine encounters the tag file tag then it sees that i'm using prefix myadvice which is a namespace for uri /myuri. the container already knows where the uri points to so when it "reads" information from the .tld file it sees the tag-file tag containing name Header and the corresponding path to .tag file. using the path it invokes the tag file. first of all am i right ?

if am right then that means the container found out the path to tag file from the .tld file. the what is the whole point about container automatically locating .tag files in /WEB-INF/tags or subdirectory or META-INF/tags or subdirectory .
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3395
312
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

now when the jsp engine encounters the tag file tag then it sees that i'm using prefix myadvice which is a namespace for uri /myuri. the container already knows where the uri points to so when it "reads" information from the .tld file it sees the tag-file tag containing name Header and the corresponding path to .tag file. using the path it invokes the tag file. first of all am i right ?


Yes, more or less. The calls to the Tag-file functionality will be included in the Java class that is made from the JSP (just have a look at the generated file). As far as I remember the container will generate a SimpleTagSupport class from every Tag-file. The calls to the generated SimpleTagSupport are then included in the generated Servlet.

if am right then that means the container found out the path to tag file from the .tld file. the what is the whole point about container automatically locating .tag files in /WEB-INF/tags or subdirectory or META-INF/tags or subdirectory


I am not sure whether I understand your question, but there are two options:
  • 1) Tag File is located in /WEB-INF/tags/ or one of its subdirectories
  • 2) Tag File is located in /WEB-INF/lib/ in a Jar file and then inside the Jar file in a directory /META-INF/tags or one of its subdirectories

  • An URI can only be used if your are trying to access a Tag-file that is located in the Jar-file. The TLD will then tell the container where to find the Tag-file.
    If you are using a Tag file located in /WEB-INF/tags (and the tagdir attribute in the JSP) the container will generate a TLD that will point to the Tag file, making the two possibilities almost equal.

    Regards,
    Frits
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic