我是 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.
与 JSP 提供的原始 scriptlet 语法相比,标记库可以更清晰地分离应用程序的外观及其逻辑。用自定义标记替换 scriptlet 消除了过去在 JSP 中常见的命令式 Java 和声明性标记的尴尬混淆。
在理想情况下,Web 设计人员将能够使用标准标记和自定义标记的组合来编辑 JSP 文件。可以将常见的标记模式分解为标记文件;如果他们需要一些需要新逻辑的东西,程序员可以为他们实现一个标签类。
实现标签库有两种方式:标签文件和标签类。标记文件使用与 JSP 几乎相同的语法,但可以使用标记中的属性进行参数化。标记类是实现特殊接口的普通 Java 类,并与标记库描述符(描述标记名称、属性和实现类的 XML 文件)捆绑在一起。
当今大多数 Java Web 框架都带有一个自定义标签库,可帮助开发人员更轻松地利用框架的功能。其他标签库,如 JSTL,提供的功能几乎适用于任何应用程序,并且可以与任何框架结合使用。