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

JWebPlus Question ID :998318336796

 
Joe Man
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following are properly formated taglib elements occuring in web.xml?
1.
<taglib>
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.tld</taglib-location>
</taglib>
2.
<taglib>
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.jar</taglib-location>
</taglib>
3.
<taglib id="ABC_MATH_LIB">
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.tld</taglib-location>
</taglib>
4.
<taglib name="ABC_MATH_LIB">
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.jar</taglib-location>
</taglib>
5.
<taglib author="ABCINC">
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.tld</taglib-location>
</taglib>
Answer: 1 and 3
Why number 2 and 4 are not correct?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3819
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4 is not correct because 'name' is not a valid attribute. 2 is correct. It should be fixed.
 
Prathap kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer 3 is not correct.
I feel Answers 1 and 2 are correct.
Correct me if i am wrong.
<taglib>
<taglib-uri>/..</taglib-uri>
<taglib-location> /...</taglib-location>
</taglib>
Regards - Prathap.
 
sanz nsgha
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so paul, what's the final answer for this? what are the valid attributes for <taglib>?
 
Long Huynh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if #2 is not correct because it is ref. a .jar, which is not standard in most IDE now, and .tld is. (WEB-INF/MathLib.jar)

-Long A. Huynh
SCJP2
 
raj sekar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that taglib can take two attributes
<taglib> The taglib element is the document root. A taglib has two attributes.
<!ATTLIST taglib
id
ID
#IMPLIED
xmlns
CDATA
#FIXED
"http://java.sun.com/JSP/TagLibraryDescriptor"
>
So options 1 & 3 are correct:
3.
<taglib id="ABC_MATH_LIB">
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.tld</taglib-location>
</taglib>
Raj
[ July 24, 2002: Message edited by: raj sekar ]
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 is wrong since if you use tld in a jar in a non-standard way (put .tld in jar META-INF dir, put jar in WEB-INF/lib dir), you have to specify the tld manually by using the jar protocol.
Read here:
http://www.jguru.com/faq/viewquestion.jsp?EID=502923
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3819
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 2 is correct. Putting the .tld file in the tag library's JAR file is indeed a very standard way as per JSP Spec 1.2 Section 7.3.1. How else would you use 3rd party tag libraries?

JSP.7.3.1 Identifying Tag Library Descriptors
Tag library descriptor files have names that use the extension �.tld�, and the
extension indicates a tag library descriptor file. When deployed inside a JAR file,
the tag library descriptor files must be in the META-INF directory, or a
subdirectory of it.
When deployed directly into a web application, the tag library
descriptor files must always be in the WEB-INF directory, or some subdirectory
of it.

Option 3 is correct because ID is an optional attribute for all kind of tags.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3819
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roseanne Zhang:
2 is wrong since if you use tld in a jar in a non-standard way (put .tld in jar META-INF dir, put jar in WEB-INF/lib dir), you have to specify the tld manually by using the jar protocol.

That is not true. You need not have an explicit mapping in web.xml if you keep the <uri> element in your .tld file (inside the jar file). This is usually the case with the third party libraries, where it is a norm to provide a <uri> element in the .tld. Of course, you can also have explicit mapping in the web.xml if you want. Refer JSP 7.3.4.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you put the jar in WEB-INF/lib with tld in META-INF, then you don't need to write the mapping in web.xml, since the container will do it for you.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3819
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry, I didn't get you. In the earlier post you said, "if you use tld in a jar in a non-standard way (put .tld in jar META-INF dir, put jar in WEB-INF/lib dir), you have to specify the tld manually by using the jar protocol"
And now you say, "If you put the jar in WEB-INF/lib with tld in META-INF, then you don't need to write the mapping in web.xml, since the container will do it for you."
Well, the idea is, you can have both ways: If you have a <uri> element in the .tld, you need not have a <taglib> element in the web.xml. However, you can specify a mapping in the web.xml too, if you want to have another mapping for the same library.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic