This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes can I do this in tlds, uris and taglibs? 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 "can I do this in tlds, uris and taglibs?" Watch "can I do this in tlds, uris and taglibs?" New topic
Author

can I do this in tlds, uris and taglibs?

Ernesto Leyva
Ranch Hand

Joined: Feb 23, 2006
Posts: 62
Hello

I have some questions about tlds, uris and taglibs I hope someone may help

1) Someone can confirm if the following declarations are equivalent?



2) Suppose I have /X.jsp with this taglib directive (assume the taglib is not declared in web.xml)



should I put "mytaglib2.tld" in A) /mytaglib2.tld or B) /WEB-INF/mytaglib.tld?

I think should be (A)

3) Assume I have a tag declared as "myTestTag" and a TLD in META-INF. Can I do this?

Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

1) Someone can confirm if the following declarations are equivalent?



These are not equivalent. The path should begin with /WEB-INF in this case.


2) Suppose I have /X.jsp with this taglib directive (assume the taglib is not declared in web.xml)



should I put "mytaglib2.tld" in A) /mytaglib2.tld or B) /WEB-INF/mytaglib.tld?

I think should be (A)

I think uri="mytaglib2.tld" is not correct way. If you want to use directly the tdl filename then it should be full path name. In this case it should be start wit /WEB-INF/
3) Assume I have a tag declared as "myTestTag" and a TLD in META-INF. Can I do this?

[/QB]

I think there is no problem with this.

Thnaks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Aleksander Zielinski
Ranch Hand

Joined: Nov 11, 2005
Posts: 127
Hi,

Sorry if I misundestood what you have written, but my English isn't very good and I wouldn't want to make it more confusing for you.

Originally posted by Ernesto Leyva:
Hello

I have some questions about tlds, uris and taglibs I hope someone may help

1) Someone can confirm if the following declarations are equivalent?




According to SCWCD Study Guide by David Bridgewater p. 538.

(...) The usual rules apply on the path cited in <taglib-location>

  • [list]if the path begins witha slash, it's a path beginning at the context root
  • if the path does't begin with a slash, it's relative path - relative to the web.xml file - so in other words, always relative to where web.xml is located, which is in the /WEB-INF directory



  • Originally posted by Ernesto Leyva:



    2) Suppose I have /X.jsp with this taglib directive (assume the taglib is not declared in web.xml)



    should I put "mytaglib2.tld" in A) /mytaglib2.tld or B) /WEB-INF/mytaglib.tld?

    I think should be (A)



    Firstly, shouldn't be there /WEB-INF/mytaglib2.tld instead of /WEB-INF/mytaglib2.tld in (B) ?

    Anyway, when using custom tags, tld in which the tag is declared should be inside WEB-INF, or inside a subdirectory of WEB-INF. You can even have as many subdirectories as you wish, and as long tld will be inside any of this subdirectories of WEB-INF you are ok. You could even put the tld inside /WEB-INF/classes/com/something/else/here/my/tag/put/it/here and it works.
    Vishnu Prakash
    Ranch Hand

    Joined: Nov 15, 2004
    Posts: 1026
    1. If the value of the <taglib-location> starts with a "/" then the container tries to locate the file relative to the document root. However if it doesn't start with a "/", then the container adds "/WEB-INF/" to the value and then tries to locate the file.

    2. Read Aleksander Zielinski reply.

    3. "uri" attribute in the taglib directive should match the "uri" element in tld file. Thats the rule. You can have any name you like.

    There is one way in which the "uri" attribute can be used as a location, but it's considered a really bad practice if you don't specify a <uri> attribute in the TLD, the container will attempt to use the "uri" attribute in the taglib directive as a path to the actual TLD.


    Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
    Jigar Gosar
    Ranch Hand

    Joined: Jul 09, 2002
    Posts: 95
    Ernesto Leyva,

    first, i dont agree with some of the answers given, as you will notice from my reply.
    second, i'll try to answer your questions as precisely as possible.

    1. confirmed. reason: if <taglib-location> doesnot begin with "/" than "/WEB-INF/" prefix is presumed.

    2. Option A is correct.
    reason: when a uri used in <%@taglib %> directive is not defined web.xml (or in some other tld within jar)than following applies.
    a. if uri is absolute (i.e has protocol, hostname) than some exception is thrown.
    b. if the uri is root relative (begning with / )than the tld must be present at corresponding path in that webapplication's context (or docroot folder)
    c. else the 'path specified by the uri' is assumed to be relative to the current page being accessed, and hence the tld file must be present 'there'.

    here opction c applies. Hence, "A) /mytaglib2.tld" is correct.

    3. yes, you can do this as long as you have a "META-INF/taglib.tld" present in the jar file containing your tag decleration.
    reason: whenever one specifies a jar file as uri (in either taglib directive or web.xml) than that jarfile must contain a "/META-INF/taglib.tld" file, which when absent throws an error complaining "taglib.tld not found".


    I am very sure of my answers, and I would appreciate if any one can correct my mistakes, if any.
    [ April 22, 2006: Message edited by: Jigar Gosar ]

    Regards,<br />Jigar Gosar (SCJP 1.4)<br />visit: <a href="http://jigar.org/blog" target="_blank" rel="nofollow">http://jigar.org/blog</a>
    Ernesto Leyva
    Ranch Hand

    Joined: Feb 23, 2006
    Posts: 62
    Hi thanks for all th answers

    I think Jigar is right.

    note: For question 1 check JSP Spec 2.0 JSP.7.3.6.1

    About question 2 yes, Aleksander Zielinski is right, it should say


    2) Suppose I have /X.jsp with this taglib directive (assume the taglib is not declared in web.xml)





    For question 2 the fallback mechanism I think will apply.

    1) the container will search in the taglib-MAP the uri
    2) if uri is not found the uri is used as the path
    3) since the path is relative with no /The container should resolve the uri relative to path of invoking JSP in this case /X.jsp

    note: I do not think the container will throw and error because tld is not
    in WEB-INF

    note: check this JSP Spec 2.0 JSP.7.3.6.2

    In question 3 I think something similar to question 2 applies the only difference is the use of a JAR file
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: can I do this in tlds, uris and taglibs?