What is taglib?

Can someone explain what taglib is in relation to Java programming? It contains a prefix and uri ... but what does each of them refer to? I looked at several different sites, but to be honest, I'm still confused about what it is and what it does.

+5
source share
3 answers

The JavaServer Page API allows you to define custom JSP tags that look like HTML or XML tags, and a tag library is a collection of custom tags that implement custom behavior.

The taglib directive states that your JSP page uses a set of custom tags, identifies the location of the library, and provides a means to identify custom tags on your JSP page.

Source: JSP - taglib Directive

+4
source

The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags that encapsulates the basic functions common to many JSP applications.

JSTL supports general, structural tasks such as iteration and conventions, tags for processing XML documents, internationalization tags, and SQL tags. It also provides the basis for integrating existing custom tags with JSTL tags.

JSTL tags can be classified according to their function into the following groups of JSTL tag libraries that you can use when creating a JSP page:

Main tags

Tag formatting

SQL tags

XML tags

JSTL Functions

Each tag group has the following kernel structure:

<%@ taglib prefix="some prefix" uri="some http URL" %> 

You can find more information here .

+1
source

Suppose you want to create a web page for which you need to write the same code for each of them many times, for example, on an e-commerce website, you may need to show price tags, size and color along with an image for each item.

You must show 10 items or more on one page. Now, instead of writing HTML code, CSS code many times, you can create something tag-lib where you can create a method in a class that accepts a list of parameters, and you can call this method.

You can embed html and css code in the method, and you can design the user interface of the page by simply writing one line of code, passing parameters to it.

0
source

Source: https://habr.com/ru/post/1208280/


All Articles