JSP Pages Using Tag Libraries

Chapter 9 - Building JSP Pages Using Tag Libraries

    JSP Pages Using Tag Libraries

  • JSP Pages Using Tag Libraries:

    The taglib directive in a JSP page declares that the page uses a tag library, uniquely identifies the tag library using a URI and associates a tag prefix.

    If a JSP container implementation cannot locate a tag library description, a fatal translation error shows the result.

    It is a fatal translation error for the taglib directive to appear after actions or functions using the prefix.

    Example:

    < %@ taglib uri="http://www.mycorp/supertags" prefix="super" % >

    < super:doMagic >
    ...
    < /super:doMagic >
    Syntax:
     < %@ taglib ( uri="tagLibraryURI" | tagdir="tagDir" ) prefix="tagPrefix" % >

    taglib Directive attributes:
    Attribute Description
    uri Either an absolute URI or a relative URI specification that uniquely identifies the tag library descriptor associated with this prefix. The URI is used to locate a description of the tag library.
    tagdir Indicates this prefix is to be used to identify tag extensions installed in the /WEB-INF/tags/ directory or a subdirectory. An implicit tag library descriptor is used. A translation error must occur if the value does not start with /WEB-INF/tags/. A translation error must occur if the value does not point to a directory that exists. A translation error must occur if used in conjunction with the uri attribute.
    prefix Defines the prefix string in that is used to distinguish a custom action, e.g . Prefixes starting with jsp:, jspx:, java:, javax:, servlet:, sun:, and sunw: ARE RESERVED. A prefix must follow the naming convention specified in the XML namespaces specification. Empty prefixes are illegal in this version of the specification, and must result in a translation error.



     

    The center of JSTL is the core taglib. This can be split into five areas:

    1. General purpose

    2. Variables support

    3. Conditional

    4. Iterator

    5. URL Related

    Use the core library, use the following directive:

     < %@ taglib prefix="c" uri="http://java.sun.com/jstl/core" % >

    The prefix attribute specifies the prefix used in the tag name for a particular library. For example, the core library includes a tag named out. When combined with a prefix of c, the full tag would be.

    use the taglib element in your web.xml file to include the tag library:

        < taglib >
    < taglib-uri > http://java.sun.com/jstl/core < /taglib-uri >
    < taglib-location > /WEB-INF/tld/core.tld < /taglib-location >
    < /taglib >

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy