Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JSP Directives

JSP Directives

JSP directives are used to set attributes related to the entire JSP page, such as the page encoding and scripting language.

The syntax format is as follows:



<%@ directive attribute="value" %>

A directive can have many attributes, which exist as key-value pairs separated by commas.

The three directive tags in JSP:

Instruction Description
<%@ page ... %> Defines page-dependent attributes, such as scripting language, error page, buffering requirements, and so on
<%@ include ... %> Includes another file
<%@ taglib ... %> Imports the definition of a tag library

The Page Directive

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

Syntax of the page directive:



<%@ page attribute="value" %>

The equivalent XML format:






property

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

property Description
buffer Specifies the size of the buffer used by the out object
autoFlush Controls the buffer of the out object
contentType Specifies the MIME type and character encoding of the current JSP page
errorPage Specifies the error-handling page to forward to when an exception occurs in the JSP page
isErrorPage Specifies whether the current page can serve as an error-handling page for another JSP page
extends Specifies the class from which the servlet inherits
import Imports the Java classes to be used
info Defines the description of the JSP page
isThreadSafe Specifies whether access to the JSP page is thread-safe
language Defines the scripting language used by the JSP page; the default is Java
session Specifies whether the JSP page uses a session
isELIgnored Specifies whether EL expressions are evaluated
isScriptingEnabled Determines whether scripting elements can be used

The Include Directive

JSP can include other files through the include directive. The included file can be a JSP file, an HTML file, or a text file. The included file is treated as part of the JSP file and is compiled and executed together with it.

The syntax of the include directive is as follows:



<%@ include file="File relative URL address" %>

include The file name in the directive is actually a relative URL.

If you do not associate a path with the file, the JSP compiler looks in the current path by default.

The equivalent XML syntax:






The Taglib Directive

The JSP API allows users to define custom tags; a custom tag library is a collection of custom tags.

The taglib directive imports the definition of a set of custom tags, including the library path and the custom tags.

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.

The equivalent XML syntax: