JSP learning notes -- JSP tag Library

Source: Internet
Author: User
Tags tld

Address: http://www.7880.com/Info/Article-461b6340.html

1. jsp (preferred for SUN Enterprise Applications) label Library (also called custom Library) can be seen as a set of methods to generate scripts based on xml (standardization is getting closer and closer), which is supported by JavaBeans. In terms of concept, the tag library is a very simple and reusable code structure. It can greatly simplify the code of entering various input boxes on the page (for example, <input type = "text" name = "taxpayerName" value = ", <select name = "collectionItemCode" class = "required" style = "width: 200 "...), and structured.

2. The Tag Library provides a simple way to create reusable code blocks. However, unlike COM and J2EE, you do not need to master any additional skills to create a tag Library: if you write a jsp (preferred for SUN Enterprise Applications) page, you will create a tag library. Finally, the tag library improves the maintainability of Web applications. This kind of maintainability improvement is manifested in the fact that the custom interfaces based on xml (standardization is getting closer and closer) are easily implemented on the jsp (preferred for SUN Enterprise Applications) page.

3. A simple tag consists of the following elements:
(1) JavaBeans: To get the object-oriented benefits of Java and Java, reusable code should be put into an independent code container. These JavaBeans are not part of the tag library. However, it is the basic code block that your code library uses to execute related tasks.
(2) Tag processing: this is the true core of the tag library. A tag processor will reference all information (pageContext object) of any resources required by it (your JavaBeans) and access your jsp (preferred for SUN Enterprise Applications) page ). The jsp (preferred for SUN Enterprise Applications) page also transmits all the configured tag attributes and the content in the TAG body on the jsp (preferred for SUN Enterprise Applications) page to the tag processor. After the tag processor completes processing, it will be sent back to your jsp (preferred for SUN Enterprise Applications) page for processing.
(3) Description of the tag Library (tld file): this is a simple xml file (standardization is getting closer and closer) that records the attributes, information, and locations of the tag processor. Jsp (preferred for SUN Enterprise Applications) Containers use this file to learn where and how to call a tag library.
(4) website web. xml (standardization is getting closer and closer) file: This is the initialization file of your website. In this file, you define custom tags used in your website, and which tld file is used to describe each custom tag.
Dispatch file (a WAR or JAR file): If you want to reuse a custom tag, you need a method to transfer it from one project to another. It is a simple and effective method to package the tag library into a JAR file.
Declare the tag library in your jsp (preferred for SUN Enterprise Applications) file: It is very simple. If you want to use this tag, you only need to declare it on the page, you can use it anywhere on this jsp (the preferred choice for SUN Enterprise Applications) page.

 

Below is an instance

1.First, write the tag processing program,ATM tag. java

//Use a tag handler to define customer tags

 

Import javax. servlet. jsp (preferred for SUN Enterprise Applications ).*;

//Import the driver of the label class

Import javax. servlet. jsp (preferred for SUN Enterprise Applications). tagext .*;

Import java. io .*;

Import java. SQL .*;

Import java. math .*;

Import java. util .*;

//ImplementationTagSupportOrBodyTagSupportInterface

Public class ATM tag extends TagSupport

{

Connection connect = null;

Statement state = null;

ResultSet result = null;

Public ATM tag () throws ClassNotFoundException

{

Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");

}

//Abstract classTagMethod, tag handler Initialization

Public int doStartTag () throws jsp (preferred for SUN Enterprise Applications) TagException

{

//GuidanceJsp (preferred for SUN Enterprise applications)The engine processes the TAG body content

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.