JSP tag library Parsing

Source: Internet
Author: User
Tags xsl xsl file tld

Why should I select JSP as my main server-side application programming tool? Of course, JSP has many fascinating features and functions, but the JSP tag library is one of the most important reasons for me to make this decision.

Why? There are two reasons: maintenance and development speed. The server-side scripting language is like a melting pot for Internet development. On a server page, you can easily mix different script methods and objects. This type of page is simply the concrete of Building Web. This combination of "Materials" provides powerful information processing capabilities for server scripts. It allows server programmers to develop dynamic and flexible Web pages. On the other hand, it is difficult to maintain a free mix of scripts, especially as the project grows. We will have to have experienced programmers build and maintain the final product. As a result, these programmers become general Web designers. Server applications are weakened in the final graphic design and implementation. What's worse, because these pages are complicated for code, and the development speed is reduced accordingly. Finally, many medium-sized or large-sized server-side Web applications were launched very late, and the cost was uncontrollable. In addition, after implementing these applications, many sellers must also find qualified programmers to maintain such messy code like a basin of pasta.

No one of us is willing to see this result. Therefore, to overcome this problem, ASP introduces the COM object technology, while JSP provides J2EE as a countermeasure. These solutions are built on a centralized, reusable code library mechanism. However, they are too difficult to use and consume a lot of time. Also, these solutions do not reduce the temptation to create messy code. As a result, we can only organize large, well-structured development teams to use these technologies. This means that even though we have all the above methods to build large projects, medium-scale projects are not patronized by these technologies.

The reality is that medium-sized projects are the main part of Web applications. Therefore, many projects have to face the situation that their development and maintenance environments cannot meet their needs.

Fortunately, JSP provides us with the best solution to this problem. The Tag library Tag libraries 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 JSP pages, you will create a tag library. Finally, the tag library improves the maintainability of Web applications. This kind of maintainability improvement is shown in the following: XML-based custom interfaces are easily implemented on JSP pages. As a result, Web designers can establish JSP Web applications without having to know what is going on with JSP. In this way, Web development becomes a very efficient team development task. JSP programmers can create custom labels and backend code modules, while Web designers can use custom labels and focus on Web design. The tag library solves the problem of code chaos and is well-rounded. In fact, XML is the essence of solving these problems, but the tag library still plays a key role ).

What is a tag library?

JSP tag library is also called custom tag) is a method for generating XML-based scripts through JavaBean. In concept, tags are simple and reusable code structures. For example, in our latest JSPKit in JSP Insider), we use XML tags to easily access XML documents. See list A below.

Listing A: Sample tag for XML/XSL conversion and Its HTML page
<% @ Taglib uri = "http://www.jspinsider.com/jspkit/JAXP" prefix = "JAXP" %>
C:/xml/example. xml
C:/xml/example. xsl

The preceding example uses simple labels to access more powerful code behind the scenes. In the above example, an XML file is first loaded, and an XSL file is applied to create a result that will be sent to the client ?? All of this is simply a simple tag.

Custom tags make it easy to create reusable open source code modules in JSP projects. All you need is the tag library and its documentation. The key features of the tag library are as follows:

Easy to install on multiple projects

Labels can be easily migrated from a JSP project to another project. Once a tag library is created, you only need to package the tag library into a JAR file to reuse it in other JSP projects. What you cannot reuse is the TAG content that you add when creating a tag as a programmer. Because tags can be reused, the tag library can be easily used for your own projects. Currently, the best tag resources can be found at JSPTags.com ..

Extends the JSP tag Library

The tag library can have any features and functions in the JSP specification (JSP 1.2. This also means that you have unlimited capabilities to expand and add powerful JSP functions without waiting for the release of the new version of JSP. So, can you cancel the JSP include call on the page ?? You only need to use the include label to create your own specifications.

Easy to maintain

The tag library makes JSP Web applications easy to maintain. There are mainly the following reasons:

Tags are easy to use and understand for anyone.

All your logic resides in the central tag processor and JavaBean. In this way, if you have to update your code, you only need to process these central files without modifying other pages that use the code.

If you need to add new features, you do not have to change any existing pages. You can include additional attributes in your tag so as to introduce new behaviors while retaining the previous attributes, so that the old page can run normally.

For example, you may have one of the following labels that make your text Blue:
My Text, but as the project goes on, you want to darken the blue. So you keep your own labels, but add a new property to them: shade
All the old labels of My Text continue to show blue, but now you can use the same label to produce the dimmed blue Text.

Tags improve code reusability. The Code that has been tested and used for multiple times must have fewer bugs. Therefore, JSP pages with custom tags also have fewer defects, making maintenance easier.

Faster development speed

The tag library is a good way to reuse code. We know that the standard method of reusing code on the server language is to use templates. Compared with the template library, the tag library is much better. To use the template library, you need to modify the template for each project or create a hardware interface. The tag library does not have these restrictions, and its object-oriented feature makes the tag library flexible in usage and extremely powerful in scalability. In addition, because you reuse the code, the time spent on project development is greatly reduced, and more time can be used to design your own Web applications. The simple interface of the tag library makes these codes easy to use and debug.

Although the tag library is very simple to use, it is much more complicated to build its internal support hierarchy than to build a simple JavaBean. The main reason for this complexity is that the tag library contains several parts. What you need to master is to understand and be familiar with Java and JSP.

Customization label Overview

A simple custom JSP tag includes the following elements:

JavaBean: to fully utilize Java's object-oriented features, reusable code should be placed in an independent code container. These JavaBean are not part of the tag library. They are the basic code modules used by the tag library to execute the assigned tasks.

Tag Processor: this is the real core of the tag library. Tag Processor tag handler) References any external material required by the tag processor JavaBean) and is responsible for accessing the information PageContext object on the JSP page ). On the JSP page, all the tag attributes set on the page are passed to the tag processor. The tag TAG content on the JSP page is also handled in this way. When the tag processor completes the processing, it returns the processed output to the JSP page for further processing.

Tag library descriptor TLD file): This is a very simple XML file. The TLD file describes and describes attributes, information, and location of the tag processor file. JSP containers use this file to map the location and usage of the called Tag library.

Web. xml file of the web site: in fact, this is the initialization file on your Web site. In this file, you can define custom tags used in Web applications and TLD files used to describe each custom tag.

Publishing WAR or JAR files): If you are planning to reuse custom tags, you certainly need to find a simple way to migrate tags from one project to another. Packaging the tag library into a JAR file is a convenient and efficient way to publish the tag library. We have not created a JAR file in the above example, but if you want to learn more about the details of the JAR file, you may wish to read "jsp war file Introduction ".

  1. Aside from JSP, start with JSF.
  2. JSF and JSP are new partners
  3. Analysis of Application in JSP program
  4. Implement JSP page and code separation using JavaBean
  5. Integrate FCKEditor in JSF/JSP

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.