• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

can I do this in tlds, uris and taglibs?

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    Ranch Hand
    Posts: 1026
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Ranch Hand
    Posts: 95
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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 ]
     
    Ernesto Leyva
    Ranch Hand
    Posts: 62
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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 once met a man from Nantucket. He had a tiny ad
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic