Home > Java > javaTutorial > what is jsp tag library

what is jsp tag library

(*-*)浩
Release: 2020-09-15 15:20:58
Original
2672 people have browsed it

what is jsp tag library

Recommended course: Java tutorial

##JSPThe Standard Tag Library (JSTL) is a collection of JSP tags that encapsulates The common core functions of JSP applications. JSTL supports common, structured tasks, such as iteration, conditional judgment, XML document operations, internationalization tags, and SQL tags. In addition to these, it also provides a framework to use custom tags integrated with JSTL. Conceptually, tags are simple and reusable code structures. For example, in the latest release of JSPKit (within JSP Insider), XML documents are easily accessed using XML tags.

Important Features

Easy to install on multiple projects

Tags are easily migrated from one JSP project to other projects. Once you create a tag library, just package everything into a JAR file that you can reuse in any JSP project. Tag libraries are becoming increasingly popular because tags can be reused and can easily be used in your own projects. Currently, the best tag resource can be found at JSPTags.com.

Can extend and increase the functions of JSP without limit

Extend JSP tag library can have any features and functions in the JSP specification (JSP 1.2), you can extend and add JSP without limit functionality without having to wait for the next version of JSP to appear. For example, you are not satisfied with the JSP include call. You can create your own include tags that enforce your own specifications.

Easy to maintain

The tag library makes JSP web applications very easy to maintain for the following reasons:

(1) Tag application is simple and suitable for any It is easy for people to use and understand.

(2) All program logic codes are concentrated in the tag processor and JavaBeans. This means that when you upgrade the code, you don't need to modify every page that uses the code. You only need to modify the centralized code files.

(3) If you need to add new functions, you do not need to modify any existing pages. You can add additional attributes to the tags to introduce new behaviors, while other old attributes remain unchanged. All old pages still work fine. For example, you have a tag that makes all text blue:

My Text

But in a later project, you want to make the blue darker. You can keep the original label, just add a new attribute: shade, as follows:

My Text

All old tags can still produce blue text, but now you can use the same tag to produce darkened blue text.

(4) Tags improve code reusability. Code that has been tested and used many times will definitely have fewer bugs. Therefore, JSP pages using custom tags also have fewer defects and are naturally much more convenient to maintain.

Fast Development Time

Tag libraries provide an easy way to reuse code. One of the standard ways to reuse code in server-side languages ​​is to use templates. Compared to using template libraries, tag libraries are a better solution. With a template library, you have to modify the templates or build a strict interface for each project, while the tag library does not have these restrictions and has all the benefits of object-oriented, can be flexible and more extensible, and, by reusing code , you can spend less time doing development and more time designing your web application. The interface of the tag library is also very simple, making it very easy to insert, use and debug.

The composition structure of tags

Although the tag library is very easy to use, the internal implementation mechanism of establishing a tag library is still quite complicated, at least it is simpler than establishing a tag library. JavaBeans are complex. The complexity comes from the fact that the tag library is composed of several parts. However, you only need to master the knowledge of Java and JSP.

A simple tag consists of the following elements:

1. JavaBean: To get the benefits of Java and its inherent object-oriented nature, reusable code should be placed in a separate code container, which is a JavaBean. These JavaBeans are not an essential part of the tag library, but they are the basic code modules used by the tag library to perform the assigned tasks.

2. Tag Processor: The tag processor is the real heart of the tag library. A tag handler references any external resources it needs (JavaBeans) and is responsible for accessing JSP page information (PageContext objects). The JSP page passes the tag attributes set on the page and the content in the tag body to the tag processor. When the tag processor completes its processing, it will send the processed output results back to the JSP page for further processing. .

3. Tag library descriptor (TLD file): This is a simple XML file that records the attributes, information, and location of the tag processor. The JSP container uses this file to know where and how to call a tag library.

4. The web.xml file of the website: This is the initialization file of the website. In this file, the custom tags used in the website need to be defined, as well as the tld file used to describe each custom tag.

5. Release files (WAR or JAR files): If you want to reuse custom tags, you need a way to move them from one project to another. Packaging the tag library into a JAR file is a simple and effective way.

6. Tag library declaration on the JSP page: If you want to use a custom tag in the JSP page, you need to use the tag library identifier to declare it on the page.

It seems that there is a lot of work to be done. Of course it will be a little tricky when you first start using it, but it is not difficult. The point is not about coding, but about organizing the pieces correctly. This hierarchical structure is important because it makes the use of tags flexible and easier to transfer. More importantly, these levels allow the entire process of creating a tag library to be automated through the JSP IDE (JSP integrated development environment). The JSP IDE can automatically complete most of the work of creating custom tags, and you only need to be responsible for setting up the code and tag processors yourself. (Note: A tag processor defines only one custom tag; a tag library is a collection of several tag processors that handle the same task)

The benefits of tag libraries are only briefly discussed in this article . Tag libraries actually have many other powerful features. Tag libraries push JSP development into an unprecedented new world. This is indeed an exciting new technology for JSP developers because they get a tool that can convert JSPs into various applications and build any type of web application. The tag library turns JSP into the richest, most dynamic development capability, and powerful Web programming environment. Its capabilities are limited only by our imagination and creativity.

The above is the detailed content of what is jsp tag library. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
jsp
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template