Easy Tutorial
❮ Jstl Core Choose Tag Jsp Sending Email ❯

JSP Directives

JSP directives are used to set attributes 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" %>

Directives can have multiple attributes, which exist in key-value pairs and are separated by commas.

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 ... %> Imports the definition of a tag library

Page Directive

The Page directive provides instructions to the container about the usage of the current page. A JSP page can contain multiple page directives.

The syntax format for the Page directive:

<%@ page attribute="value" %>

Equivalent XML format:

&lt;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 when an exception occurs in 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 the access to the JSP page is thread-safe
language Defines the scripting language used in the JSP page, default is Java
session Specifies whether the JSP page uses session
isELIgnored Specifies whether to execute EL expressions
isScriptingEnabled Determines whether scripting elements can be used

Include Directive

JSP can include other files using the include directive. The included file can be a JSP file, HTML file, or text file. The included file is treated as part of the JSP file and is compiled and executed together.

The syntax format for the Include directive is as follows:

<%@ include file="relative url address of the file" %>

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

If you do not associate a path with the file, the JSP compiler defaults to searching in the current path.

Equivalent XML syntax:

&lt;jsp:directive.include file="relative url address of the file" />

Taglib Directive

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

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

The syntax for 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:

&lt;jsp:directive.taglib uri="uri" prefix="prefixOfTag" />
❮ Jstl Core Choose Tag Jsp Sending Email ❯