2

when we use the Compiler directive below and I don't use in web.xml

<%@ taglib uri="/struts-tags" prefix="s"%>

what will tomcat do with that? How the taglib find the .tld? Does it have a search sequence? I want to know the principle. thx~

koppt
  • 21
  • 1
  • 3

2 Answers2

5

Here's the way it works:

The JAR file that contains your tag library has a .tld file, which in turn has a <uri> tag with a string that needs to match the value in your JSP.

For example, the standard JSTL JAR has a c.tld file with this URI:

<uri>http://java.sun.com/jsp/jstl/core</uri>

That's the URI that you need to use the core JSTL tag library.

It has nothing to do with where you put the JARs and everything to do with the .tld.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • I don't quite understand, can you say more detailed. I know it use the tag to match the value in my JSP, but how can it find the JAR file which has the .tld? – koppt Apr 09 '12 at 15:16
  • I disagree - you don't "know" it uses the tag value, because what you posted is wrong. See the docs: http://struts.apache.org/1.x/userGuide/configuration.html. As for how, the JAR is in your CLASSPATH - either the /lib directory of your app server or the WEB-INF/lib of your WAR. – duffymo Apr 09 '12 at 15:20
  • Can I think: the .tld in the JAR has a , and <%@ taglib...> will match its with .tld 's , if same then get the tag? So the Compiler will search the JAR in my CLASSPATH and find the right .tld? – koppt Apr 09 '12 at 15:42
  • If by "compiler" you mean the JSP compiler, then the answer is "yes". – duffymo Apr 09 '12 at 15:44
0

The container search for all .tld in your web Application,First in the WEB-INF directory, next in all subdirectory of WEB-INF, and if there is a jar file he search inside it ,if there is a tld file. After that, the container map every uri found with the tld file.

Hatim
  • 1,116
  • 1
  • 8
  • 14