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 web dependency properties, 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 attributes related to the Page directive:
Attribute | Description |
---|---|
buffer | Specify the size of the buffer to be 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 the error handling page for another JSP page |
extends | Specify the class from which the servlet inherits |
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 |
sessão | Especificar se a página JSP deve usar sessão |
isELIgnored | Especificar se as expressões EL devem ser executadas |
isScriptingEnabled | Determinar se o elemento de script pode ser usado |
O JSP pode incluir outros arquivos usando a instrução include. O arquivo incluído pode ser um arquivo JSP, arquivo HTML ou arquivo de texto. O arquivo incluído parece ser uma parte do arquivo JSP, e será compilado e executado ao mesmo tempo.
A forma de formato da gramática da instrução include é a seguinte:
<%@ include file="endereço url relativo do arquivo" %>
include O nome do arquivo na instrução é realmente um endereço URL relativo.
Se você não associar um caminho ao arquivo, o compilador JSP padrão procurará no caminho atual.
Gramática XML equivalente:
<jsp:directive.include file="endereço url relativo do arquivo" /> />
A API do JSP permite que os usuários personalizem tags, e uma biblioteca de tags personalizada é uma coleção de tags personalizadas.
A instrução taglib introduce a definição de um conjunto de tags personalizadas, incluindo o caminho da biblioteca e as tags personalizadas.
Gramática da instrução taglib:
<%@ taglib uri="uri" prefix="prefixOfTag" %>
O atributo uri determina a localização da biblioteca de tags, e o atributo prefix especifica o prefixo da biblioteca de tags.
Gramática XML equivalente:
<jsp:directive.taglib uri="uri" prefix="prefixOfTag"> />