English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Directivas de JSP

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:

DirectiveDescription
<%@ 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

Page directive

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" /> />

Attribute

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

AttributeDescription
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
sesión Especificar si la página JSP utiliza sesión
isELIgnored Especificar si se debe ejecutar la expresión EL
isScriptingEnabled Determinar si se puede usar el elemento de script

Instrucción include

JSP puede incluir otros archivos mediante la instrucción include. El archivo incluido puede ser un archivo JSP, archivo HTML o archivo de texto. El archivo incluido parece ser una parte de este archivo JSP y se compilará y ejecutará simultáneamente.

El formato del formato de la instrucción include es el siguiente:

<%@ include file="ruta relativa url archivo" %>

include El nombre del archivo en la instrucción es una dirección URL relativa.

Si no ha asociado una ruta al archivo, el compilador de JSP buscará por defecto en la ruta actual.

Gramática XML equivalente:

<jsp:directive.include file="ruta relativa url archivo" /> />

Instrucción taglib

La API de JSP permite a los usuarios personalizar etiquetas, y una biblioteca de etiquetas personalizada es una colección de etiquetas personalizadas.

La instrucción taglib introduce una definición de conjunto de etiquetas personalizadas, incluyendo la ruta de la biblioteca y las etiquetas personalizadas.

Gramática de la instrucción taglib:

<%@ taglib uri="uri" prefix="prefixOfTag" %>

El atributo uri determina la ubicación de la biblioteca de etiquetas, y el atributo prefix especifica el prefijo de la biblioteca de etiquetas.

Gramática XML equivalente:

<jsp:directive.taglib uri="uri" prefix="prefixOfTag"> />