Implementation of JSP system: Template Library and tag Library

Source: Internet
Author: User

The following describes how to implement the template library and tag library in the JSP system.

The Planning and Design of the tag library is crucial in the whole system design. It relates to the degree of code reuse and the efficiency of system operation. Its planning should follow the following principles.

1) The tag should contain as few static HTML as possible. Generally, tags are transparent. You cannot view or modify tags. If the label contains too many static HT-ML statements, it will affect the user to modify and improve the static effect of the page, limit the use of the label.

2) try to improve code reuse. To classify JSP applications, try to extract common JSP applications to form tags. Instead of repeating the application in each tag. In this way, you only need to modify the label to facilitate code maintenance when you need to modify and improve the application in the future.

3) easy to use. When designing the tag library, you should fully consider the user's usage, so that users can easily and conveniently understand and use tags.

① Tag library definition: to define a tag library, you must first define a tag library to describe the file TLD ). This is an XML-based script file, this file defines the XML version, the encoding used, the tag library version, the JSP version used, the tag library name, and all the tags contained in this library. definition and parameter description, includes the tag name, the Java class corresponding to the tag, and the description of the tag.

② Tag implementation: a tag is a special Java

Class, which must inherit the TagSupport class, which is defined in the javax. servlet. jsp. tagext package. The tag class contains the parameter initialization method Set/Get of the tag, the main processing method Handler of the tag, and the method for calling the next-level tag.

③ Template implementation: a template is a JSP file containing tag reference. To reference a defined tag in a template, you must first introduce the tag library.

<% @ Taglib uri = "tag. tld" prefix = "ctag" %>

The uri specifies the path of the tag library description file, and the prefix specifies the prefix used when the tag is referenced.

When a tag is referenced in a template, the prefix specified when the tag library is introduced is used to specify the Tag Name and assign values to the tag parameters.

  1. Four components of the JSP system
  2. Introduction to JSP syntax
  3. Introduction to the Forward and sendRedirect methods of JSP
  4. Use JSP pages to generate PDF reports
  5. Step for customizing JSP labels

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.