2

When using JSTL tags in .jsp files or jsf facelets you have to declare the tag libraries you want to use.

Example (jsp):

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

Example (jsf):

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

It is always said that the URI does not play any role other than making the namespace unambiguous and to provide additional documentation. I do not believe this. I know that the facelet/.jsp does not load any information from the URI via the internet. But the correct URI must be somehow used to identify the correct tag library.

Could someone explain how this is done?

I checked this: If you change only one letter in the URI you get an exception:

org.apache.jasper.JasperException: /todolist.jsp(10,61) PWC6188: 
The absolute uri: http://java.sux.com/jsp/jstl/core cannot be resolved
in either web.xml or the jar files deployed with this application
Kukeltje
  • 11,924
  • 4
  • 19
  • 44
RamsesGE
  • 33
  • 8
  • You kind of already give the answer yourself (emphasis mine). _"does not **load** any information from the URI via the internet. But the correct URI must be somehow used to **identify** the correct tag library"_ Exactly the difference between a URL (L= locator) and URI (I=Identifier) – Kukeltje Jul 08 '15 at 11:57
  • Yes, but this URI is in fact a URL. What makes things a bit misleading is that it is not locating the tag library, but only the tag library documentation. My question was, how the URI is used to locate the tag library (which has been answered below). Most people say, it is only used to give the namespace an unambiguous name, you could also call it "johnDoe". This is not rue. The URI is strictly linked to the name/identifier that has been explicitly given to the tag library. – RamsesGE Jul 09 '15 at 10:50
  • Nope, it has the format you are used to from a URL http://stackoverflow.com/questions/176264/what-is-the-difference-between-a-uri-a-url-and-a-urn. There is no 'locating/loading' of of the resource here. It is just 'identifying'. It cannot have just any name, it has to conform to the definition (see the uri info tab). And it is used to give something an unambiguous namespace. But it only needs to refer to something else (taglib, xsd etc) IF it is used in that way. – Kukeltje Jul 09 '15 at 11:05
  • Thanks for the links. What I understood: A URL is a special URI that contains information about where an identified resource is available and the mechanism for retrieving it. In our case e.g. `http://www.w3.org/1999/xhtml` is a URL for the XHTML documentation only. It contains the mechanism for retrieving (http://) but this is not used. My question has arised from the fact that in the jsf case the `xmlns` attribute uses a URI looking like a URL but does not reveal the mechanism for retrieving the tag library. – RamsesGE Jul 10 '15 at 07:28
  • Correct and it does not need to since it is just an identifier, not a locator – Kukeltje Jul 10 '15 at 07:30

1 Answers1

0

The URI is defined within the taglib defintion file. Without the correct URI the reference cannot be resolved. It is like a name or key.

For example the core.tld

<description>JSTL 1.2 core library</description>
  <display-name>JSTL core</display-name>
  <tlib-version>1.2</tlib-version>
  <short-name>c</short-name>
  <uri>http://java.sun.com/jsp/jstl/core</uri>

Also you could define the URI for custom taglibs within the web.xml

<taglib>
  <taglib-uri>http://lelelu.org/mytag-io</taglib-uri>
  <taglib-location>/WEB-INF/mytags-io.tld</taglib-location>
</taglib>
benliet
  • 90
  • 1
  • 1
  • 6
  • Thanks for your answer. One more question: Why do you find this sometimes in web.xml, sometimes in .tld file? Where do I find the core.tld? – RamsesGE Jul 09 '15 at 09:20
  • You can download the source code of JSTL from the maven repo. [link](http://search.maven.org/#browse|-1002239620) you can use a definition in web.xml for your own TagLibs. – benliet Jul 10 '15 at 13:00