JSP directive


JSP instructions are used to set properties related to the entire JSP page, such as the encoding method and scripting language of the web page.

The syntax format is as follows:

<%@ directive attribute="value" %>

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

Three types of instruction tags in JSP:

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

Page directive

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

Page directive syntax format:

<%@ page attribute="value" %>

Equivalent XML format:

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

Attributes

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

AttributesDescription
buffer Specify the size of the buffer used by the out object
autoFlush Control the buffer area of ​​the out object
contentType Specify the MIME type and character encoding of the current JSP page
errorPage Specify the error handling page that needs to be redirected when an exception occurs on the JSP page
isErrorPage Specify 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 be used
info Define the description information of the JSP page
isThreadSafe Specifies whether access to the JSP page is thread-safe
language Define the scripting language used by the JSP page. The default is Java
session Specify whether the JSP page uses session
isELIgnored Specify whether to execute EL expression
isScriptingEnabled Determine whether script elements can be used

Include directive

JSP can include other files through the include directive. The included files can be JSP files, HTML files or text files. The included files act as if they were part of the JSP file and will be compiled and executed at the same time. The syntax format of the

Include directive is as follows:

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

include The 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 search in the current path by default.

Equivalent XML syntax:

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

Taglib directive

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

The Taglib directive introduces the 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" />