%@ 在 jsp 中的用途

The purpose of %@ in jsp

我在写 jsp 页时总是添加以下行:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

但是 <%@ %> 通常是什么意思?我知道我们可以通过 scriptlet

将代码嵌入到 jsp
<% \some java code %>

所以 @taglib 看起来像是应用于 prefix 的注释。正确吗?

这是一个JSP directive

JSP directives provide directions and instructions to the container, telling it how to handle certain aspects of JSP processing. A JSP directive affects the overall structure of the servlet class. It usually has the following form:

 <%@ directive attribute="value" %>

<%@ >JSP - Directives 的标签,可以是:

  • Page directive <%@ page ... %> :定义页面相关的属性,比如 脚本语言、错误页面和缓冲要求。

  • Include 指令 <%@ include ... %> : 在翻译阶段包含一个文件。

  • Taglib 指令 <%@ taglib ... %> :声明一个标签库,包含自定义操作, 在页面中使用。

它是一个 JSP Directive.The JSP 指令是告诉 web 容器如何将 JSP 页面翻译成相应的 servlet.The 标签库的消息指令是JSP directive.The JSP taglib指令之一,用于定义一个标签库,其中定义了很多标签。