<taglib> element in the Web application deployment descriptor is used to...
1. specify a URI identifying a tag library.
2. specify the mapping of the name and the TLD file for a tag library. 3. specify the parameters needed by a tag library.
4. specify the TLD file location.
5. specify the mapping of TLD file and the library.
The correct answer is 2.
I have a doubt in the given explanation from enthuware. Please consider it:-
The <taglib> tag comes directly under the web-app element and it is used to specify the mapping between the name that will be used in the JSP pages and the URI where the actual tag library descriptor (.tld file) is located.
<!ELEMENT taglib (taglib-uri, taglib-location)>
<taglib-uri>/mylibrary</taglib-uri> ( You can use 'mylibrary' in the JSP taglib directive : <%@taglib uri="/mylibrary" prefix=="mylib"%> )
<taglib-location>/WEB-INF/tlds/MYLibrary.tld</taglib-location> // This is the location of tld file for the tag library.
This is a flexible way to specify the use of a tag library in a web application. Java classes implementing the tag library can be put into webapp in 2 ways:
1. Make a jar file of all the classes and include *.tld files in META-INF directory inside the jar. You can drop this jar file in WEB-INF/lib of the webapp.
In this case, you need not specify any <taglib> tag in the web.xml. The servlet container will automatically inspect the *.tld file in the jar file and for each <uri> element in the tld, it will add <taglib> (internally) tag in web.xml.
2. Keep un-jared classes in WEB-INF/classes. You can keep the *.tld at any place where the web application can access it but you have to specify that in the <taglib-location>. Eg. If you put mylib.tld in WEB-INF then you should give: <taglib-location>/WEB-INF/mylib.tld</taglib-uri>
As per my knowledge 2 point is not correct, as JSP 2.0 container automatically map uri-name and TLD by looking the .TLD files at the allowed location.
you not reuire to get the explicit mapping in web.xml file. Am i correct??