This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
SCJP2, SCWCD 1.4
Joined: Sep 05, 2005
Hi Sai How come uri element is optional? we have to match the uri attribute in taglib directive of JSP to the uri element of TLD.right??? And also how do we declare tag files in TLD???
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 ]
Hai Sai, uri attribute of taglib directive is not mandatory ,I think. We can tagdir (incase of tagfiles) instead.
SCJP, SCWCD, SCBCD
Joined: Sep 05, 2005
Hi Vishnu Prakash, Thanks for your reply. But <jsp-config><taglib> is not used in mapping taglib uri to a TLD file in current JSP 2.0 spec. I think. What do you say??
And uri is just a made-up name Right??So how do you map a uri to a TLD file??? thanks for your response
Joined: Nov 15, 2004
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.