JSP tag library introduction (1) Custom label insider

zhaozj2021-02-08  237

A simple custom label includes the following elements:

JavaBean: In order to take advantage of Java's object-oriented characteristics, the reuse code should be placed in a separate code container. These JavaBeans are not part of the label library. They are the base code module for label libraries to perform allocated tasks. Label processor: This is the real core of the label library. The tag processor references the JavaBean it needs and is responsible for accessing the JSP page (PageContext object). The JSP page passes the tag properties set on the page to the label processor, and the contents of the label label on the JSP page are also processed. When the label processor completes its processing, it will send the processed output to the JSP page for further processing. Tag library descriptor (TLD file): This is a very simple XML file, TLD file description and explanation of information such as properties, information, and label processor file locations. The JSP container uses this file to map the location and usage of the called tag library. Web site web.xml file: actually this is the initialization file on your web site. In this file you can define custom tags used in a web application, or define a TLD file used to describe each custom tag. Publish file (WAR or JAR file): If you plan to retrofit tags, then you must need a simple way to migrate the label from a project to other projects. Pack the label library into a JAR file is this convenient and efficient label library release method. We did not build a JAR file in the above case, but if you plan to learn more about the details of the JAR file, you may wish to read the "JSP WAR File Introduction". The label library declaration on the JSP page: just use the tag label to easily declare the labels on the page. After the label library declares on the page, you can use them at will.

It seems that you will be busy, it is actually not so bad. Of course, it will be a bit tricky when you start using it. In fact, the true key is not encoded but corrects the above parts correctly. This hierarchical structure is very important, and it is so that the label library and flexible are easy to use. More important things, these levels allow the entire establishment of the label library to be automatically completed through the JSP IDE. The future JSP IDE can automatically complete most of the work of creating custom labels, and you only need to establish code and label processors.

(Note: A label processor only defines a custom label; and a label library is a collection of many label processors, which performs the same task.)

转载请注明原文地址:https://www.9cbs.com/read-2302.html

New Post(0)