How to reference the tag library repost in JSP

Source: Internet
Author: User
Tags tld
If you are using a container that complies with JSP 1.2/servlet 2.3, such as Tomcat 4.x or higher, you can use the absolute path in the taglib command of the JSP page instead of the web. specify the taglib element in XML.

You still need to declare all the JSP labels you use in Web. xml before the servlet 2.3 specification. The following code snippet from the Web. xml deployment descriptor shows the typical taglib Declaration for struts applications:
<! -- Struts tag library descriptors -->
<Taglib>
<Taglib-Uri>/tags/Struts-bean </taglib-Uri>
<Taglib-location>/WEB-INF/struts-bean.tld </taglib-location>
</Taglib>
<Taglib>
<Taglib-Uri>/tags/Struts-HTML </taglib-Uri>
<Taglib-location>/WEB-INF/struts-html.tld </taglib-location>
</Taglib>
<Taglib>
<Taglib-Uri>/tags/Struts-logic </taglib-Uri>
<Taglib-location>/WEB-INF/struts-logic.tld </taglib-location>
</Taglib>
<Taglib>
<Taglib-Uri>/tags/Struts-nested </taglib-Uri>
<Taglib-location>/WEB-INF/struts-nested.tld </taglib-location>
</Taglib>

After servlet 2.3, the absolute URI of the tag library is specified in the tag library Descriptor (TLD) file of the library. For example, the following is the corresponding statement in the struts-bean.tld file:
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype taglib public "-// Sun Microsystems, Inc. // dtd jsp tag
Library 1.1 // en "" http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd ">
<Taglib>
<Tlibversion> 1.0 </tlibversion>
<Jspversion> 1.1 </jspversion>
<Shortname> bean </shortname>

<URI> http://jakarta.apache.org/struts/tags-bean </uri>

Any page that needs to use this tag library can be referenced using the following page-level commands. The tag library does not need to be referenced in the web. xml file:
<% @ Taglib
Uri = "http://jakarta.apache.org/struts/tags-bean"
Prefix = "Bean" %>

If you use the same tag library in the entire application, you can use the method described in the basic action to create a JSP file containing the general tag library declaration command. If you reference a tag library that is not required, it will not cause too much performance loss. Therefore, you can safely include this file on each JSP page. If the URI changes, you only need to modify one location instead of each JSP file.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.