JSP 中的 TAG 库有什么用以及我们为什么使用它?

发布于 2024-08-07 06:11:08 字数 75 浏览 2 评论 0原文

我是 JSP 新手,我接触过标签库,请给我一些标签库的详细解释,我们应该在哪里以及什么类型的应用程序中使用它?

提前致谢

I am new to JSP and i've come accross Tag libraries, Please give me some detail explaination of tag libraries, where and what type of application we should use that?

Thanks in advancve

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘羡 2024-08-14 06:11:08

标签库是根据您的要求使用的,例如,当您需要的内容超出了使用 EL 和标准操作所能完成的范围时。标签库包含可以根据您的需要使用的自定义标签,您甚至可以创建自己的自定义标签(这是一个很大的过程,需要您编写在 JSP 中使用自定义标签时运行的 java 代码) ,在大多数情况下,JSTL 中的可用标签就足够了。

退一步说,JSP 中使用标签是为了将脚本(java 代码)与 jsp 页面分开,即无脚本页面有助于维护性,因为表示与逻辑是分离的,甚至可以帮助那些不懂的网页设计者。懂得java来美化jsp页面,而不必处理jsp页面中嵌入的java代码。

我建议您阅读 'Head First Servlet & JSP' 以便更好地理解整个过程。

Tag Libraries are used based upon your requirement, say, when you need more than what can be done using EL and standard actions. The tag libraries contain custom tags that can be used as per your need and you can even create your own custom tags(that is a big process & requires you write the java code that is run when you use your customized tag in the JSP), in most cases, the available tags in the JSTL would be sufficient.

Stepping a step backward, tags are used in JSPs in order to separate the scripts(java code) from the jsp pages, ie, script-free pages help in maintainability as presentation is separated from logic, and it even helps web page designers who dont know java to beautify the jsp pages without them having to deal with the java code embedded in the jsp pages.

I suggest you read 'Head First Servlets & JSP' for a better understanding of the entire process.

清眉祭 2024-08-14 06:11:08

与 JSP 提供的原始 scriptlet 语法相比,标记库可以更清晰地分离应用程序的外观和逻辑。用自定义标记替换 scriptlet 消除了 JSP 中常见的命令式 Java 和声明性标记的尴尬混淆。

在理想的情况下,Web 设计人员将能够使用标准标记和自定义标记的组合来编辑 JSP 文件。常见的标记模式可以分解为标记文件;如果他们需要一些需要新逻辑的东西,程序员可以为他们实现一个标签类。

实现标签库有两种方法:标签文件和标签类。标记文件使用与 JSP 几乎相同的语法,但可以使用标记中的属性进行参数化。标签类是实现特殊接口的普通 Java 类,并与标签库描述符(描述标签名称、属性和实现类的 XML 文件)捆绑在一起。

如今,大多数 Java Web 框架都附带自定义标签库,可帮助开发人员更轻松地利用框架的功能。其他标记库(例如 JSTL)提供的功能几乎适用于任何应用程序,并且可以与任何框架结合使用。

Tag libraries allow a cleaner separation between the look-and-feel of your application and its logic, compared to the original scriptlet syntax offered by JSP. Replacing scriptlets with custom tags eliminates the awkward confusion of imperative Java and declarative markup that used to be common in JSPs.

In an ideal world, web designers would be able to edit JSP files using a combination of standard markup and custom tags. Common markup patterns can be factored out into tag files; if they need something that requires new logic, a programmer can implement a tag class for them.

There are two ways to implement a tag library: tag files, and tag classes. Tag files use a syntax that is nearly the same as JSP, but can be parameterized with attributes in the tag. Tag classes are normal Java classes that implement a special interface, and bundled with a Tag Library Descriptor—an XML file that describes the tag name, attributes, and implementation class.

Most Java web frameworks today come with a custom tag library that helps developers utilize the features of the framework more easily. Other tag libraries, like JSTL, provide functionality that is useful in almost any application, and can be used in conjunction with any framework.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文