问题
I am cofused between tagdir
and uri
used in taglib
directive.
What is the real difference between using tagdir
and uri
?
Examples :
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="notMyTags" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="otherTags" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="myTags" %>
to the best of my understanding:
1) I can access non-custom tags from the uri
referencing them by the provided prefix
(e.g.: if the uri
defines the tag hello
, in the page where taglib-uri
is pasted, I can access it as <notMyTags:hello>
or <otherTags:hello>
).
2) I can access custom tags defined within the path specified in tagdir
referencing them by their .tag
filenames because each custom tag corresponds to a .tag
file (e.g.: if hello.tag
is a file in the tagDir
specified path, in the page where taglib
is pasted, I can access it as <myTags:hello>
)
回答1:
The two directive are used for two different concepts of custom JSP tags.
1) You use uri
to reference a tag library, which is usually delivered in a jar and/or defined in a .tld
file. These can be written in Java (implementing one of the `javax.servlet.jsp.tagext.JspTag' subinterfaces) or as plain JSP tagfiles.
2) You use tagdir
to reference JSP tagfiles within /WEB-INF/tags
(or subdirectories thereof). Those can not be Java classes.
See the J2EE tutorial at Orcale's website for more information regarding JSP tagfiles: http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPTags5.html
来源:https://stackoverflow.com/questions/38893729/what-is-the-difference-between-uri-and-tagdir-in-jsp-taglib