JSP taglib 自定义标签 tld web.xml 笔记
2013-11-03 11:35
691 查看
http://docs.oracle.com/javaee/5/tutorial/doc/bnalj.html Java EE 5 Tutorial 的说明。(Java EE 7太新,不符合现在所学,故没有引用7的链接)
http://www.cnblogs.com/zhaoyang/archive/2011/12/25/2301108.html
http://wiki.metawerx.net/wiki/Web.xml
==============================================================
http://wiki.metawerx.net/wiki/Web.xml.JspConfig
This parent element wraps one or more <taglib> elements and <jsp-property-group>
elements.
Note that in Tomcat 6 and earlier, <taglib> did not need to be inside <jsp-config>. However on Tomcat 7, context will fail to load with the following error if you specify <taglib> elements outside of a <jsp-config> element. This occurs even if you specify an
earlier web-app version in your web.xml, so can be confusing when migrating to Tomcat 7.
<taglib>
- contains examples
<jsp-property-group>
- contains examples
Removing
taglib from web.xml - The <taglib> section is no longer required in web.xml since
JSP 2.0 / Servlets 2.4.
TLD
Files - DTD and XSD - JSP 2.0 uses XSD declarations, see examples here for TLD files
===========================================================
http://wiki.metawerx.net/wiki/RemovingTaglibFromWeb.xml
JSP 1.2 required the <taglib> directive to be used in web.xml for every JSP
Custom Tag Library used by the application. In JSP 2.0 this is no longer required. This guide shows how to get rid of your <taglib> directives and how JSP 2.0 finds TLD files.
The <taglib> directive looks like this. You will find one in web.xml for older
versions of Struts, and any other software which uses tag libraries in JSP 1.2.
Since JSP 2.0, this is now optional.
The TLD is discovered automatically when the taglib is first referenced in a JSP file.
The actual JSP 1.2 TLD files themselves are upwardly compatible with JSP 2.0, so do not need to be modified.
JSP 2.0 containers such as Tomcat 5.5 search for TLD files in the following places:
The following locations are searched:
<appName>/WEB-INF folder
All subfolders of <appName>/WEB-INF
Inside each JAR file in <appName>/WEB-INF/lib, in the META-INF folder of the JAR. This method is prefered for easy deployment of a JAR containing a taglib.
Place TLD files in a folder named META-INF, at the root level of the JAR
file. eg:
This example copies TLD files from src dir into your compiled-classes dir, then includes them in the <jar> elements. In this case, we are making two JAR files, containing
all files from the com.yourCompanyName.jsputil and waptools folders, and including the relevant TLD file in each JAR. You could also combine to make a single jar file, with both TLDs included.
For library developers, distribution is now simpler as packaging is as simple as including the TLD file in the JAR
file.
For end-users, deployment and re-use is simpler, as a tag library JAR file can
simply be dropped into the WEB-INF/lib folder with no web.xml configuration
required.
The TLD file does not need to have the same name as the library. For example, your mytags library definition can be in a file called mytaglist.tld. However, for easier identification
later, it is good practise to use the same name as you intend to use in the JSP files. For example, if you plan to reference your library as mytags, with <mytags:testtag> in JSP, call the file mytags.tld.
The <short-name> element in the TLD file does not need the same name as the library. Once again, for easier maintenance and to avoid potential clashes, it is good practise to use the
same name. For example <short-name>mytags</short-name>.
The <uri> in the TLD file is the main reference for matching JSP declarations with the correct TLD. When automatically finding TLD files, the container matches the uri attribute in your
JSP taglib declaration with the <uri> tag in the TLD file. Ensure this is always unique to avoid clashes. For example:
Many older applications still include the <taglib> directive in web.xml.
If your application falls into this category, try removing it and check if everything still works. Don't forget to move your TLD file into WEB-INF, or preferably into your JAR
file. Your web.xml will be simpler, and the Tag Library will be more modular
(easier to remove from the app, replace, or reuse).
In older applications, the TLD file is sometimes in a separate folder, such as in the example above (/WEB-INF/jsp/mytaglib.tld). In this case, move the file into the JAR
file if possible. TLD files will still work from subfolders of WEB-INF, but since the location of the TLD files is no longer recorded in web.xml,
it can make them harder to find when debugging your system later - especially after a few months of not looking at it, or if someone else is trying to debug your code. It therefore makes sense to either include them in the JAR
file which contains the classes for the tag, or at least place them in an easy to notice location such as a subfolder called WEB-INF/tld or WEB-INF/taglibs.
The following pages have solutions to exceptions you may encounter when working with Custom Tag Libraries.
org.apache.jasper.JasperException
org.xml.sax.SAXException
javax.servlet.ServletException
web.xml Reference
Guide
其它链接:
http://blog.csdn.net/yhawaii/article/details/7218062
http://www.cnblogs.com/zhaoyang/archive/2011/12/25/2301108.html
http://wiki.metawerx.net/wiki/Web.xml
==============================================================
http://wiki.metawerx.net/wiki/Web.xml.JspConfig
<jsp-config>
This parent element wraps one or more <taglib> elements and <jsp-property-group>elements.
Note that in Tomcat 6 and earlier, <taglib> did not need to be inside <jsp-config>. However on Tomcat 7, context will fail to load with the following error if you specify <taglib> elements outside of a <jsp-config> element. This occurs even if you specify an
earlier web-app version in your web.xml, so can be confusing when migrating to Tomcat 7.
IllegalArgumentException: taglib definition not consistent with specification version
Child-elements:
<taglib>- contains examples
<jsp-property-group>
- contains examples
See Also
Removingtaglib from web.xml - The <taglib> section is no longer required in web.xml since
JSP 2.0 / Servlets 2.4.
TLD
Files - DTD and XSD - JSP 2.0 uses XSD declarations, see examples here for TLD files
===========================================================
http://wiki.metawerx.net/wiki/RemovingTaglibFromWeb.xml
Removing <taglib> from web.xml
Author: Neale Rudd, Metawerx
Date: 16-Nov-2006
JSP 1.2 required the <taglib> directive to be used in web.xml for every JSPCustom Tag Library used by the application. In JSP 2.0 this is no longer required. This guide shows how to get rid of your <taglib> directives and how JSP 2.0 finds TLD files.
The <taglib> directive looks like this. You will find one in web.xml for older
versions of Struts, and any other software which uses tag libraries in JSP 1.2.
<taglib> <taglib-uri>mytags</taglib-uri> <taglib-location>/WEB-INF/jsp/mytaglib.tld</taglib-location> </taglib>
Since JSP 2.0, this is now optional.
The TLD is discovered automatically when the taglib is first referenced in a JSP file.
The actual JSP 1.2 TLD files themselves are upwardly compatible with JSP 2.0, so do not need to be modified.
Where does JSP look for the TLD files?
JSP 2.0 containers such as Tomcat 5.5 search for TLD files in the following places:The following locations are searched:
<appName>/WEB-INF folder
All subfolders of <appName>/WEB-INF
Inside each JAR file in <appName>/WEB-INF/lib, in the META-INF folder of the JAR. This method is prefered for easy deployment of a JAR containing a taglib.
How should I package my JAR file?
Place TLD files in a folder named META-INF, at the root level of the JARfile. eg:
META-INF/ mytags.tld com/ yourCompanyName/ yourTag1.class yourTag2.class yourTag3.class
ANT build.xml example
This example copies TLD files from src dir into your compiled-classes dir, then includes them in the <jar> elements. In this case, we are making two JAR files, containingall files from the com.yourCompanyName.jsputil and waptools folders, and including the relevant TLD file in each JAR. You could also combine to make a single jar file, with both TLDs included.
<!-- Copy TLD files into the out.dir, so all files for the JAR are in the same place --> <copy todir="${out.dir}/META-INF"> <fileset dir="${src.dir}/META-INF"> <include name="**.tld" /> </fileset> </copy> <!-- Create the jsputil jar file --> <jar jarfile="${dist.dir}/jsputil.jar" basedir="${out.dir}" includes="com/yourCompanyName/jsputil/** META-INF/jsputil.tld" /> <!-- Create the waptools jar file --> <jar jarfile="${dist.dir}/waptools.jar" basedir="${out.dir}" includes="com/yourCompanyName/waptools/** META-INF/waptools.tld" />
Why is this better?
For library developers, distribution is now simpler as packaging is as simple as including the TLD file in the JARfile.
For end-users, deployment and re-use is simpler, as a tag library JAR file can
simply be dropped into the WEB-INF/lib folder with no web.xml configuration
required.
TLD Tips in JSP 2.0
The TLD file does not need to have the same name as the library. For example, your mytags library definition can be in a file called mytaglist.tld. However, for easier identificationlater, it is good practise to use the same name as you intend to use in the JSP files. For example, if you plan to reference your library as mytags, with <mytags:testtag> in JSP, call the file mytags.tld.
The <short-name> element in the TLD file does not need the same name as the library. Once again, for easier maintenance and to avoid potential clashes, it is good practise to use the
same name. For example <short-name>mytags</short-name>.
The <uri> in the TLD file is the main reference for matching JSP declarations with the correct TLD. When automatically finding TLD files, the container matches the uri attribute in your
JSP taglib declaration with the <uri> tag in the TLD file. Ensure this is always unique to avoid clashes. For example:
This declaration in your JSP ... <%@ taglib prefix="mytags" uri="http://metawerx.net/taglibs/mytags" %> Will match this element in your TLD ... <uri>http://metawerx.net/taglibs/mytags</uri>
Upgrading your application
Many older applications still include the <taglib> directive in web.xml.If your application falls into this category, try removing it and check if everything still works. Don't forget to move your TLD file into WEB-INF, or preferably into your JAR
file. Your web.xml will be simpler, and the Tag Library will be more modular
(easier to remove from the app, replace, or reuse).
In older applications, the TLD file is sometimes in a separate folder, such as in the example above (/WEB-INF/jsp/mytaglib.tld). In this case, move the file into the JAR
file if possible. TLD files will still work from subfolders of WEB-INF, but since the location of the TLD files is no longer recorded in web.xml,
it can make them harder to find when debugging your system later - especially after a few months of not looking at it, or if someone else is trying to debug your code. It therefore makes sense to either include them in the JAR
file which contains the classes for the tag, or at least place them in an easy to notice location such as a subfolder called WEB-INF/tld or WEB-INF/taglibs.
Debugging TLD Deployment
The following pages have solutions to exceptions you may encounter when working with Custom Tag Libraries.org.apache.jasper.JasperException
org.xml.sax.SAXException
javax.servlet.ServletException
See Also
web.xml ReferenceGuide
其它链接:
http://blog.csdn.net/yhawaii/article/details/7218062
相关文章推荐
- 自定义JSP中的Taglib标签之六Taglib中常用的属性值与tld常用标签简介与web.xml设置自定义标签的uri
- [教程]自定义JSP中的Taglib标签之六Taglib中常用的属性值与tld常用标签简介与web.xml设置自定义标签的uri
- Taglib中常用的属性值与tld常用标签简介与web.xml设置自定义标签的uri
- Taglib标签之六Taglib中常用的属性值与tld常用标签简介与web.xml设置自定义标签的uri
- 【Java.Web】JSP —— 标签库taglib —— 自定义JSP标签 —— 标签库描述文件 TLD,发布
- JSP 2.0 web.xml不再直接支持<taglib>标签配置
- JSP 2.0 web.xml不再直接支持<taglib>标签配置
- JavaEE自定义标签:标签类的创建、tld配置文件的创建(位置、如何创建)、Web-XML配置、JSP应用
- 【Java.Web】JSP —— 标签库taglib —— 第三方标签库 —— JSTL XML
- 【Java.Web】JSP —— 标签库taglib —— 自定义JSP标签 —— 基础
- 【Java.Web】JSP —— 标签库taglib —— 自定义JSP标签 —— JSP Tag API
- 【Java.Web】JSP —— 标签库taglib —— 自定义JSP标签 —— 其他
- 【Java.Web】JSP —— 标签库taglib —— 自定义JSP标签 —— 示例
- web笔记九:jsp脚本、jsp标准动作、EL表达式、JSTL标签
- 自定义JSP中的Taglib标签之自定义标签中的Function函数
- jsp:自定义标签实例(TLD)
- 自定义JSP中的Taglib标签之一简单入门篇(无参数的自定义标签)
- web.xml JSP <jsp-config>标签
- JSP学习笔记之三——关于servlet配置web.xml出现的问题
- jsp tld 的tag 自定义标签扩展