I've questions regarding <uri> element and <taglib> element in TLD. 1. How many <uri> elements we can have in a TLD.(i think it is only one).Is it correct??? 2.How many <taglib> elements we can have in a TLD?(i think this is also one). Am i correct?
taglib is only once and is mandatory element. Mandatory sub elements of taglib are tlib-version and, short-name. uri is optional and if appears only once. tag sub element is 0 or more, so is listener & tag-file.
to locate the TLD file. You can even use the uri attribute in the taglib directive to locate the path of the TLD file, but it is considered a bad practice. [ December 02, 2005: Message edited by: Vishnu Prakash ]
You got to understand the basic need of uri. It is just a name thats used to map(link) the jsp page's Tags with JSTL(or)Custom handlers that are defined in the TLD file. For example if the page is request by the user and when the container comes across the tags in that page where will it find the code that implements the tags functionality. All this definition is done in TLD file(About the tag handler class thats invoked, its name, attributes, whether it is allowed to have body-content) But there has to be something that maps(links) the JSP Page to the TLD file. And that process is carried out by the uri.
The usual way of mapping a jsp page to a TLD would be having a uri attribute that holds the same value that of uri element in the TLD. But uri element in TLD file is optional which brings us a interesting question which you had asked in your second post in this thread.
Now proceed with my reply. <jsp-config> element is defined in DD. In that way you can locate the TLD file. In <taglib-uri> you specify the uri name and with <taglib-location> you specify the actual location of the TLD file.
For example <jsp-config> <taglib> <taglib-uri>MyURI</taglib-uri> <taglib-location>/WEB-INF/MyTldFile.tld</taglib-location> </taglib> </jsp-config>
You can even use the uri attribute in the taglib directive to locate the path of the TLD file, but it is considered a bad practice.