Tag library

from Wikipedia, the free encyclopedia

Tag libraries are part of the JSP specification. With the use of Java Server Pages it has already been achieved that only a little Java code is needed to create a dynamic web page. However, JSPs are not free from Java code and are therefore difficult to edit for web designers .

With the help of tag libraries it is possible to develop JSP pages that contain little or no Java code. Such JSP pages then provide the interface between the web designer who doesn't understand Java and the developer who develops the dynamic parts of a page. Tag libraries can also be used in multiple JSP pages.

A tag library consists of a collection of tag classes and a tag library description (TLD). Tag classes are Java classes that implement a specific interface. The TLD indicates which class is responsible for each tag and which attributes it offers. In the JSP, these special tags can be integrated in XML notation, e.g. B .: <mylib:mytag myattr1="25" myattr2="xyz"/>. The Java code is thus outsourced from the JSP side to the tag class.

As soon as the processing of a JSP page reaches the start or end identifier of a tag, the servlet engine calls certain methods on the tag class. The tag class can then perform calculations in the Java code, read or write data from a persistence layer or write additional HTML code to the response page.