java 什么是标签库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27279217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 11:32:45  来源:igfitidea点击:

What is a taglib?

javataglib

提问by Daron

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.

有人能解释一下关于 Java 编程的 taglib 是什么吗?它包含一个前缀和 uri...但是它们分别指的是什么?我查阅了许多不同的网站,但坦率地说,我仍然对它是什么以及它做什么感到困惑。

采纳答案by K.Nicholas

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.

JavaServer Pages API 允许您定义看起来像 HTML 或 XML 标记的自定义 JSP 标记,而标记库是一组实现自定义行为的用户定义标记。

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.

taglib 指令声明您的 JSP 页面使用一组自定义标记,标识库的位置,并提供一种方法来识别 JSP 页面中的自定义标记。

Original source: JSP - The taglib Directive

原始来源:JSP - taglib 指令

回答by Yegor Korotetskiy

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

JavaServer Pages 标准标记库 (JSTL) 是一组有用的 JSP 标记,它封装了许多 JSP 应用程序通用的核心功能。

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.

JSTL 支持常见的结构化任务,例如迭代和条件、用于操作 XML 文档的标签、国际化标签和 SQL 标签。它还提供了一个将现有自定义标记与 JSTL 标记集成的框架。

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:

JSTL标签根据其功能可以分为以下JSTL标签库组,可以在创建JSP页面时使用:

Core Tags

核心标签

Formatting tags

格式化标签

SQL tags

SQL 标签

XML tags

XML 标签

JSTL Functions

JSTL 函数

Each group of tags has the following core structure:

每组标签具有以下核心结构:

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

More info you can find here.

您可以在此处找到更多信息。

回答by nikhilmeth

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.

您必须在单页中显示 10 个或更多项目。现在,无需多次编写 HTML、css 代码,您可以创建一些 tag-lib,您可以在其中创建一个接受参数列表的类的方法,并且您可以调用该方法。

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.

您可以在方法中嵌入 html 和 css 代码,只需编写一行代码并传递参数即可设计页面的 UI。