what is the difference between uri and tagdir in JSP taglib

你离开我真会死。 提交于 2019-12-12 18:36:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!