16

Can someone explain what a taglib is in respect to Java programming? It contains a prefix and uri...but what do each of these refer to? I looked up a number of different websites but am frankly am still confused about what it is and what it does.

Daron
  • 329
  • 1
  • 4
  • 24

3 Answers3

14

The JavaServer Pages API allows you to define custom JSP tags that look like HTML or XML tags and a tag library is a set of user-defined tags that implement custom behavior.

The taglib directive declares that your JSP page uses a set of custom tags, identifies the location of the library, and provides a means for identifying the custom tags in your JSP page.

Original source: JSP - The taglib Directive

K.Nicholas
  • 10,956
  • 4
  • 46
  • 66
1

The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.

JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags. It also provides a framework for integrating existing custom tags with JSTL tags.

The JSTL tags can be classified, according to their functions, into following JSTL tag library groups that can be used when creating a JSP page:

Core Tags

Formatting tags

SQL tags

XML tags

JSTL Functions

Each group of tags has the following core structure:

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

More info you can find here.

0

Let’s imagine you want to create a web page which needs you to write same code many times for each particular like in e commerce website, you might have to show price tags, size and color along with an image for each item.

You have to show 10 items or more in single page. Now, instead of writing the HTML, css code many times, you can create something tag-lib where you can create a method in a class which accepts a list of parameters and you can call that method.

You can embed html and css code in the method and you can design the UI of the page by just writing a single line of code by passing parameters to it.

deilkalb
  • 445
  • 1
  • 4
  • 10