JSP directives

The JSP directive is used to set the properties of the entire JSP page, such as the encoding of the web page and the scripting language.

The syntax is as follows:

<%@ directive attribute="value" %>

Instructions can have many properties, they exist as key-value pairs, separated by commas.

Three instruction tags in JSP:

Instructions Description
<%@ page ... %> Define web page dependency properties such as scripting language, error page, cache requirements, etc.
<%@ include ... %> Include other files
<%@ taglib ... %> Introduce the definition of the tag library

Page command

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

The syntax of the Page directive:

<%@ page attribute="value" %>

Equivalent XML format:

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


The following table lists the properties associated with the Page directive:

Properties Description
Buffer Specify the size of the buffer used by the out object
autoFlush Control the out object Cache area
contentType Specify the MIME type and character encoding of the current JSP page
errorPage Specifies the error handling page that needs to be redirected 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 Specify which class the servlet inherits from
Import Import the Java class to use
Info Defining the description of the JSP page
isThreadSafe Specify whether access to JSP pages is thread safe
Language The scripting language used to define the JSP page. The default is Java
Session Specify whether the JSP page uses session
isELIgnored Specify whether to execute an EL expression
isScriptingEnabled Determine if script elements can be used

Include directive

JSP can include other files with the include directive. The included file can be a JSP file, an HTML file, or a text file. The included files are like part of the JSP file and will be compiled and executed at the same time.

The syntax of the Include directive is as follows:

<%@ include file="Relative file url address" %>

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

If you do not associate a path to a file, the JSP compiler defaults to finding it under the current path.

Equivalent XML syntax:

<jsp:directive.include file="Relative file url address" />

Taglib instruction

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

The Taglib directive introduces a definition of a custom tag collection, including library paths 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" />