English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JSP directives are used to set properties related to the entire JSP page, such as the encoding method of the web page and the script language.
The syntax format is as follows:
<%@ directive attribute="value" %>
Directives can have many attributes, which exist in the form of key-value pairs and are separated by commas.
There are three types of directive tags in JSP:
Directive | Description |
---|---|
<%@ page ... %> | Define the dependent properties of the web page, such as script language, error page, caching requirements, etc. |
<%@ include ... %> | Include other files |
<%@ taglib ... %> | Introduce the definition of the tag library |
The Page directive provides usage instructions for the current page to the container. A JSP page can contain multiple page directives.
The syntax format of the Page directive is:
<%@ page attribute="value" %>
The equivalent XML format is:
<jsp:directive.page attribute="value" /> />
The following table lists the properties related to the Page directive:
Property | Description |
---|---|
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 to be redirected to when an exception occurs in 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 | Specify whether the access to the JSP page is thread-safe |
language | Define the script language used by the JSP page, the default is Java |
session | Specify whether the JSP page uses session |
isELIgnored | Specify whether to execute EL expressions |
isScriptingEnabled | Determine whether the script element can be used |
JSP can include other files using the include directive. The file to be included can be a JSP file, HTML file, or text file. The included file is as if it is 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="file relative url address" %>
include The filename in the directive is actually a relative URL address.
If you have not associated a path with the file, the JSP compiler will default to searching in the current path.
Equivalent XML Syntax:
<jsp:directive.include file="file relative url address"> />
JSP API allows users to define custom tags, and 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.
Taglib Directive Syntax:
<%@ 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"> />