JSP tag library introduction
I have been programmed with JSP and ASP. In these two server-side programming solutions, I am more and more practical than ASP is much better than ASP. Why should I choose JSP to choose the preferred server-side web application development tool? Of course, JSP is fascinating, but the JSP label library is one of the most important causes of this decision. Why do you say this way? There are two aspects: maintenance and development speed. The server-side scripting language is actually a furnace that develops Internet. On a server page, you can easily mix a variety of different script methods and objects. This page is simply a concrete for building web. It is this "material" mixed to give the server-side script powerful information processing power. It allows server-side programmers to develop dynamic, flexible web pages. However, on the other hand, the free mixing of the script also has its disadvantage, which is very troublesome, especially as the scale of the project is growing. Worse, as the complexity of the code increases, the speed of development will slow down, which is not conducive to developing medium and large web applications, many medium-size or large server-side web applications are available very late and cost also Unable to control. In addition, once the development is completed, the site also finds qualified programmers to maintain these quite complicated code. As a result, these programmers have become a general web designer, and the server-side application is in the final graphic design and implementing these two aspects. It is weakened. In order to overcome this problem, ASP introduced COM object technology, and JSP provides J2EE as a countermeasure. These solutions are built on the centralized and reusable code library. However, they can be too difficult to use, and there is a lot of time spent on learning. Also, these solutions do not reduce the temptation of the establishment of chaos code. As a result, we can only organize a large, internal structure well-structured development team to use these technologies. For medium projects, usually use such methods less, but in fact, medium web application projects are most. Therefore, many projects have to use a development and maintenance environment that does not meet their needs. Fortunately, JSP provides a better way to solve this problem. Tag libraries offers a simple way to build reusable code blocks. Once the label is designed, it can be used again in many projects. More convenient, unlike COM and J2EE, as long as you know how to write JSP, you can build a label library without learning any other techniques! Finally, the label library also improves the maintenance of the web application. This improvement in maintenance is: easily implements XML-based customizable interfaces on the JSP page. The results can be imagined that the web designers can establish JSP web applications without knowing what JSP is going. In this way, Web development has become a very efficient team development task. JSP programmers can establish custom labels and backend code modules, while web designers can use custom labels and fully focus on the web design itself. The label library solves the problem of code confusion, and is clean and beautiful (in fact, XML is to solve the essence of these issues, but the label library still has a considerable role).
What is a label library? The JSP tag library (also known as custom label library) can be seen as a method of generating XML-based scripts through JavaBean. Conceptually, the label is a very simple and reusable code structure. For example, in our latest JSPKIT (in JSP Insider), use the XML tab to achieve easy access to the XML document. Please see the following list A. Listing A: Example tab of XML / XSL conversion and its HTML page <% @ Taglib URI = "http://www.jspinsider.com/jspkit/jaxp" prefix = "jaxp"%>
2. Extending the JSP tag library can have any features and features in the JSP specification (JSP 1.2), you can extend and increase the functionality of JSP without restrictions without limiting, without waiting for the next version JSP. For example, you are not satisfied with JSP's include call. You can build your own include label, which is your own specification.
3. Easy to maintain the label library makes JSP web applications are very easy to maintain, and the reasons are: (1) Label application is simple, easy to use for anyone, easy to understand. (2) All program logic code is set in the label processor and JavaBeans. This means that when you upgrade the code, there is no need to modify each page that uses the code, you only need to modify the code file. (3) If you need to add a new feature, you don't need to modify any already existing pages, you can join additional properties in the tab, which introduces new behaviors, and other old properties constant, so all old pages can be normal work. For example, you have a label that lets all texts to be blue:
4. Fast Development Time Label provides a simple way to reuse code. In the language of the server, one of the standard reuse code is used to use the template. The label library is a better solution relative to the template library. With template libraries, you must modify templates for each project or create strict interfaces, and label libraries do not have these limits, and have all object-oriented benefits, you can make flexible and more scalability, and by reuse You can spend less time to develop, more time can be used in designing your web application. The label library interface is also very simple, it is very easy to do insert, use and debug. The structure of the label is very easy to use, but it is quite complicated to build a label library, but the at least is complicated than the establishment of a simple JavaBean. This complex is from the label library consists of several parts. However, you only need to master the knowledge of Java and JSP. A simple label consists of the following elements: 1. JavaBean: In order to get Java and the top-oriented benefits, reusable code should be placed in a separate code container, which is JavaBean. These JavaBeans are not an essential part of the label library, but they are the base code module for label libraries to perform allocated tasks. 2. Label processor: The label processor is the true core of the label library. A tag handler refers to any external resource (JavaBean) it needs and is responsible for accessing information on the JSP page (pageContext object). The JSP page passes the tag attributes set on the page and the contents in the label to the label processor. After the label processor completes its processing, it will send the processed output result to the JSP page to further process . 3. Label library descriptor (TLD file): This is a simple XML file that records information such as properties, information, and location of the label processor. The JSP container learns from this file and how to call a label library. 4. Web site web.xml file: This is an initialization file for the web site. In this file, you need to define the custom labels used in the Web site, and the TLD files used to describe each custom label. 5. Publish file (WAR or JAR file): If you want to reuse custom labels, you need a way to migrate it from a project to other projects. Packing the label library as a JAR file is a simple and effective way. 6. Label Library Declaration on the JSP page: To use a custom label in the JSP page, you need to use the tag library marker on the page on the page. It seems that there is a lot of work to do, and it will be a bit tricky when I started using it, but it is not very difficult. It is not yet encoded, but how to properly organize each part. This hierarchical structure is important, which makes the label flexible and easier to transfer. More important things, these levels can make the entire establishment of label libraries automatically complete through JSP IDE (JSP integrated development environment). JSP IDE can automate most of the work of creating custom tags, and you only need to be responsible for establishing code and label processors.
(Note: A label processor only defines a custom label; a label library is a collection of label processors that handle the same task) Create your first tab to teach you step by step to teach you how to build a custom label. The specific example is extended JSP, which has its own HTML encoding function. This feature replaces all
In this example, the logic for HTML encoding is common, so put in the JavaBean, please refer to the list B List B: HTML encoded javabean / * html_format.java * / public class html_format extends Object imports java.io.serializable {/ ** Create a new HTML_FORMAT * / PUBLIC HTML_FORMAT () {} / ** Replace all
Creating a label descriptor We need to describe a custom label to let the system know how to handle it. The suffix of this description file is .TLD, TLD file usually naming with a label processor and stores under the "/ web-inf /" directory. Please refer to the list D. Listing D: HTML Code Label Descriptor XML Version = "1.0" Encoding = "UTF-8"?> .0>