wood burning stoves*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes uri element ,taglib element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "uri element ,taglib element" Watch "uri element ,taglib element" New topic
Author

uri element ,taglib element

shanthisri mocherla
Ranch Hand

Joined: Sep 05, 2005
Posts: 119
Hello ,

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?

Thanks in advance
Shanthi
Sai Patnala
Ranch Hand

Joined: Jan 09, 2002
Posts: 60
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
shanthisri mocherla
Ranch Hand

Joined: Sep 05, 2005
Posts: 119
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???


thanks
Shanthi
[ December 01, 2005: Message edited by: shanthisri mocherla ]
Sai Patnala
Ranch Hand

Joined: Jan 09, 2002
Posts: 60
JSP Specification Page 400. TLD section.

You are right, uri is mandatory as attribute to taglib but not in the TLD file.

I hope i did not confuse you!
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Even if you don't specify uri element in TLD you can use other ways to locate the TLD file.

You can use <jsp-config> element in DD, like

<jsp-config>
<taglib>
<taglib-uri>
<taglib-location>
<taglib>
<jsp-config>

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 ]

Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Prathibha Bharathi Alam
Greenhorn

Joined: Dec 01, 2005
Posts: 13
Hai Sai,
uri attribute of taglib directive is not mandatory ,I think.
We can tagdir (incase of tagfiles) instead.

Regards,
Prathibha.


Regards, Prathibha
SCJP, SCWCD, SCBCD
shanthisri mocherla
Ranch Hand

Joined: Sep 05, 2005
Posts: 119
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

shanthi
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
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.

By this I mean you can do something like

<% @taglib prefix="mine" uri="/WEB-INF/MyTldFile.tld" %>

Which will help the container to locate the TLD file in your directory structure.

Note: Your TLD file can live in(or) exist in four place/location of your webapp structure.

[ December 02, 2005: Message edited by: Vishnu Prakash ]
[ December 02, 2005: Message edited by: Vishnu Prakash ]
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

And also how do we declare tag files in TLD???


<% @taglib prefix="mine" tagdir="/WEB-INF/MyTagFiles" %>

To include tag files in JSP we use "tagdir" attribute
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: uri element ,taglib element
 
Similar Threads
TLD uri doubt
Mock Exam Question
can somebody explain this with eg
tag library deployed as .jar required web.xml mapping??
How many uri can have in single .tld file???