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" %>
A directive can have multiple attributes, which exist in the form of key-value pairs and are separated by commas.
Three types of instruction tags in JSP:
instruction | describe |
---|---|
<%@ page ... %> | Define web page dependency attributes, such as script language, error page, cache requirements, etc. |
<%@ include ... %> | include other files |
<%@ taglib ... %> | Import the definition of tag library |
The Page directive provides the container with usage instructions for the current page. A JSP page can contain multiple page instructions.
The syntax format of the Page command:
<%@ page attribute="value" %>
Equivalent XML format:
<jsp:directive.page attribute="value" />
The following table lists the properties related to the Page directive:
property | describe |
---|---|
buffer | Specifies the size of the buffer used by the out object |
autoFlush | Control the cache area of out objects |
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 | 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 classes 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 | Specifies whether to execute EL expressions |
isScriptingEnabled | Determine whether script elements can be used |
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="relative url" %>
The file name in the Include directive is actually a relative URL. If you do not associate a path with the file, the JSP compiler defaults to looking in the current path.
Equivalent XML syntax:
<jsp:directive.include file="relative url" />
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.
Syntax of 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" />