This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes Tag Files : why TLD requires Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Tag Files : why TLD requires " Watch "Tag Files : why TLD requires " New topic
Author

Tag Files : why TLD requires

Jitin Guglani
Greenhorn

Joined: Jan 01, 2009
Posts: 17
hi all
i have small doubt regarding tagfiles. It is specified that if the tagfile is residing inside the jar then we require a TLD in which we use the <path> to tell the container the location of the tag file. However when we use the tag file then we write in the jsp as

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

this is what we write in the jsp file to use the tagfile.

Now I have two questions regarding it

1) If we can specify the tag file location as above then why dont we can specify the tag file location for the tag files which are packed in the jar. ie

<%@ taglib prefix="mine" tagdir="/META-INF/tags" %>

if this is possible then there is always one standard way of telling the container about the location of the tag file.

2) and if we need TLD ( any ways: for the case where tag file is in jar ) then what should be the value of the tagdir = ? in the jsp file to use the tag file.
thanks in advance
jitin
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Jitin.
1) If we can specify the tag file location as above then why dont we can specify the tag file location for the tag files which are packed in the jar. ie

<%@ taglib prefix="mine" tagdir="/META-INF/tags" %>


If the tag file is not present in jar file, we can use 'tagdir' attribute, specifying where the location of tag file is present i.e by using tagdir="/WEB-INF/tags". Now the container/server goes there and search for tag file.

If the tag file is present in jar, we should place it under /WEB-INF/lib/ directory(like /WEB-INF/lib/myTagFile.jar). If we say tagdir="/META-INF/tags", it will not able to find the tag file. Inorder to search for tag file, the container must need a reference, where the actual tag file is present. That's why we use .tld file for specifying the location of the tag file.
2) and if we need TLD ( any ways: for the case where tag file is in jar ) then what should be the value of the tagdir = ? in the jsp file to use the tag file.

In that case I think, we should not use 'tagdir' attribute. We should use 'uri' attribute instead, as incase of JSTL tags usage.
Jitin Guglani
Greenhorn

Joined: Jan 01, 2009
Posts: 17
Hi chinmaya
thanks for your reply. My question is exactly what your repsonse is ie why container is not able to lacate the tag file if it is inside the jar file because if container is able to do this simple job then there is one universal way of specifying the tag file location and it helps me remember less for the exam .So i was asking actually that why container is not able to locate from jar file even though it can read the jar.
Second as you said that instead of specifying the tag-dir specify the uri but uri is for the tags not for tag-files i think. Kindly check this again.
thanks and regards
Jitin
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Have you checked what the JSP Specification has to say about this?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jitin Guglani
Greenhorn

Joined: Jan 01, 2009
Posts: 17
No. I am very new and amature to read the specs . I was going through Head First Servlets and JSPs .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Whenever you have "why" questions such as this, the JSP Specification is the source of all knowledge.
Jitin Guglani
Greenhorn

Joined: Jan 01, 2009
Posts: 17
yes sir i know that jsp spec is the ultimate authority and i would love to read it as it is the Bible of JSP , but for the time being till I am not able to collect the information regarding this from jsp spec, if you know the answer please tell me so that I can continue my chapter without break.
I will give you my promise to finish the spec once i will finish the book
thanks and regards
jitin
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

The simple answer is that the Spec doesn't say that's the way it will work. So it doesn't.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18125
    
    8

"I don't have time to read the documentation" is never a valid excuse.
Jitin Guglani
Greenhorn

Joined: Jan 01, 2009
Posts: 17
sir I think that you have either not read my question and my replies carefully or you do not understand my problem.
The only difference is that tag-file is jar and container is able to read the jar then why we need to implement in the different way ie why JSP designers choose to implement this in the special way . what were conditions that forced them to have such a different method.
I do not see any limitation of the containers to read the jar file. why cannot we simply define the location of the jar file with tag-dir attribute.
I got your point that specs says that it is the way but my question is why this way is required.
Jitin Guglani
Greenhorn

Joined: Jan 01, 2009
Posts: 17
Mr Paul
I have never said that I dont have time to read the specs. I said that I am not that mature to read the specs. I am an amture . And gradually I will become mature to read the specs.
As a matter of fact I am going through some simpler book Head First Servlets and JSP so that I will have overall look and feel of JSP and then have to move on specs as Mr Bear has suggested.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Jitin Guglani wrote:but my question is why this way is required.

You'll need to ask the authors of the Spec for that.

There could be literally thousands of questions along the lines of "why did they do this?", or "why did they do that?".

In some cases we might be able to take a good technical guess as to why the Spec was couched in a certain way, but for many the answer is just "That's what was decided upon."
Jitin Guglani
Greenhorn

Joined: Jan 01, 2009
Posts: 17
Yes Mr Bear , I totally agree with you. but I thought by chance if some know (or some Jsp designer who is member of this site ) about it and my doubt will be clearified. But any how thanks a lot for valuable time.
regards
Jitin
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Jitin.

Second as you said that instead of specifying the tag-dir specify the uri but uri is for the tags not for tag-files i think.

As far I know we should use 'uri' attribute if the tag file is present in jar file. Please correct me, if I made mistake.

why container is not able to lacate the tag file if it is inside the jar file because if container is able to do this simple job then there is one universal way of specifying the tag file location

Container can locate, there is no problem. First thing we should remember is tag file's are created to simplify the job of page designers.

Suppose we made a tagFile named it with Image.tag and store it in package 'com.pack1.foo.bar.Image.tag'. We compile it, (here if we don't make .tld file for specifying where the tag file is present) and made a jar file named 'imageTagFile.jar'. Inorder to use this 'imageTagFile.jar' file in one of our jsp's, we have to use the page directive like Then container will be able to search for the tag file and serves our purpose. As a java programmer specifying the above page directive is simple. For page designer's it is not. Their main role is for creating creative, beautiful web pages. They don't need to know java.

Inorder to simplify the role of page desiners, I think 'sun' made a .tld file, specifying where the location of tag file is present. By using this, it is simple to use, we simply specify tag directive like
This way is simple for page designers.
Jitin Guglani
Greenhorn

Joined: Jan 01, 2009
Posts: 17
hi chinmaya.
I think this is the most logical and appropriate reason. That is why the designers design it in this way. . And yes with tag-files we can use uri.
thanks and regards ( and yeah Happy Diwali )
Jitin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tag Files : why TLD requires
 
Similar Threads
uri element ,taglib element
Unable to use tag file deployed in jar file
What will the "tagdir" attribute be for a tag file inside /META-INF/tags of a jar?
Tag Files
taglib-directive tagdir and uri