eHow launches Android app: Get the best of eHow on the go.

How To

How to Create Custom Tags in JSP

Contributor
By Javanx3d
eHow Contributing Writer
(0 Ratings)

Java Server Pages (JSP) are used to provide server-generated web pages to the end user. JSP has an extensive library of predefined JSP tags, but also enables the developer with the means to create custom tags. When a custom tag is used on a JSP page, the tag is converted to an operation on an object that is referred to as a "tag handler" when the Java Servlet is executed by the server. Custom tags can be customized as well as accessed by any Java object that is available for a JSP page to use. Custom JSP tags are defined in a tag library descriptor file that is stored with the associated Java servlet.

Difficulty: Moderately Challenging
Instructions

Things You'll Need:

  • Java Integrated Development Environment (IDE)
  1. Step 1

    Open your Java Integrated Development Environment (IDE) and create a new "Tag Library Descriptor" (TLD) file. A TLD file is an XML document that is used to create the custom tag and associated information for the tag.

  2. Step 2

    Create the "taglib" header tag that contains information such as the version number of the tag, JSP version being used, short name of the tag, and additional information for the tag library.

  3. Step 3

    Add the custom tag after the header information in the TLD file. The name of the tag will be the element value for the <name> tag.

  4. Step 4

    Choose the Class to use for the custom tag in the subsequent <tagclass> element. The fully qualified package naming convention must be used for the Class name if you are using the Java package convention. An example of this convention would be: "com.demandmedia.JSPTagExample.

  5. Step 5

    Include desired JSP tag body information after the Class declaration. No body information is required, however, you can include meta information such as a message or version in the body. An example of a body declaration is:
    <info>
    My First JSP Custom Tag
    </info.

  6. Step 6

    Save the TLD file after you have filled in the body information and your first JSP custom tag is complete.

Post a Comment

Post a Comment
  • Have you done this? Click here to let us know.
I Did This

Related Ads

Tags
Computers
Alexia Petrakos,

Meet Alexia Petrakos eHow's Computers Expert.

Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

eHow Computers
eHow_eHow Technology and Electronics