JSP Directive

JSP directives are used to set properties related to the entire JSP page, such as the page's encoding method and scripting language.

The syntax format is as follows:

<%@ directive attribute="value" %>

A directive can have many attributes, which exist in the form of key-value pairs and are separated by commas.

The three types of directive tags in JSP:

Directive Description
<%@ page ... %> Defines page-dependent attributes, such as scripting language, error page, caching requirements, etc.
<%@ include ... %> Includes other files
<%@ taglib ... %> Introduces the definition of a tag library

Page Directive

The Page directive provides the container with usage instructions for the current page. A JSP page can contain multiple page directives.

The syntax format of the Page directive:

<%@ page attribute="value" %>

Equivalent XML format:

<jsp:directive.page attribute="value" />

Attributes

The following table lists the attributes related to the Page directive:

Attribute Description
buffer Specifies the size of the buffer used by the out object
autoFlush Controls the buffer of the out object
contentType Specifies the MIME type and character encoding of the current JSP page
errorPage Specifies the error handling page to redirect to when an exception occurs on the JSP page
isErrorPage Specifies whether the current page can be used as an error handling page for another JSP page
extends Specifies which class the servlet inherits from
import Imports the Java classes to be used
info Defines the description information of the JSP page
isThreadSafe Specifies whether access to the JSP page is thread-safe
language Defines the scripting language used by the JSP page, default is Java
session Specifies whether the JSP page uses session
isELIgnored Specifies whether to execute EL expressions
isScriptingEnabled Determines whether script elements can be used

Include Directive

JSP can include other files through the include directive. The included file can be a JSP file, HTML file, or text file. The included file is treated as if it were a part of the JSP file, and is compiled and executed at the same time.

The syntax format of the Include directive is as follows:

<%@ include file="文件相对 url 地址" %>

includeThe file name in the directive is actually a relative URL address.

If you do not associate a path with the file, the JSP compiler will look for it in the current path by default.

Equivalent XML syntax:

<jsp:directive.include file="文件相对 url 地址" />

Taglib Directive

The JSP API allows users to define custom tags. A custom tag library is a collection of custom tags.

The Taglib directive introduces the definition of a custom tag collection, including the library path and custom tags.

The syntax of the Taglib directive:

<%@ taglib uri="uri" prefix="prefixOfTag" %>

The uri attribute determines the location of the tag library, and the prefix attribute specifies the prefix of the tag library.

Equivalent XML syntax:

<jsp:directive.taglib uri="uri" prefix="prefixOfTag" />
Other Extensions