Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

no need for <taglib> tag in the web.xml

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Complete the statement:

<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)>

Example:

<taglib>
<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.
</taglib>

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??

Please provide your feedback

thanks
Poonam
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please quote your sources.
 
Oscar Costa
Ranch Hand
Posts: 31
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Poonam,

From JSP 2.0 you don't need to put <taglib> in the DD. You need to keep the TLD files in correct place.
But this tag is used to maintain compatibility.
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Christophe,
This question from Enthuware Mock. please provide your input.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic