Jsp2 custom tag

Source: Internet
Author: User
Tags tld

Jsp2 custom tag

To open a custom tag in jsp:

1. Development of custom tag processing class

2. Create a *. tid file. Each tld tag corresponds to a tag library, and each tag library corresponds to multiple tags.

3. Use tags in jsp


* *** Precautions for developing custom tag classes:

1. The custom label class should inherit a parent class javax. servlet. jsp. tagext. SimpleTagSupport

2. If the custom label class contains attributes, each attribute should have the corresponding getter/setter method.

3. Override the doTag () method. This method is used to generate page content.

Example:

Public class HelloWorldTag extends simpleTagSupprt {

// Rewrite the doTag () method

Public void doTag () throws JspException, IoException {

This. getJspContext (). getOut (). write ("Hello World" + new Date ())

}

}

* *** Create a TLD tag

TLD is the abbreviation of Tag Library Definition, that is, Tag Library Definition.

We can copy a file template \ webapps \ examples \ WEB_INF \ jsp2 in tomcat contains a jsp2-example-taglib.tld

Copy the file to the web application's WEB-INF path and make simple modifications

Example:

Root Node:

Tag:


* *** Use tags <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + signature + MqGkILHqx6nD + signature + PGJyPgo8L3A + CjxwPsq508Ox6sepv + signature + MaGkILW8yOux6sepv + signature/Signature "http://tomcat.apache.org/debug-taglib" prefix = "mytag" %>

Uri: The uri of the tag library.

Prefix: short name

2. Use tags; use custom tags in jsp

Because of

TAGDEPENDENT Empty TAG body defined

We only need to call:

Prefix + Tag Name

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.