Page Directive
Defines attributes that apply to an entire JSP page.
JSP Syntax
<%@ page [ language="java" ][ extends="package.class" ][ import="{package.class | package.*}, ..."][ session="true|false" ][ buffer="none|8kb|sizekb" ][ autoFlush="true|false" ][ isThreadSafe="true|false" ][ info="text" ][ errorPage="relativeURL" ][ contentType="mimeType[ ; charset=characterSet]" |"text/html ; charset=ISO-8859-1"][ isErrorPage="true|false" ][ pageEncoding="characterSet | ISO-8859-1" ] [ isELIgnored="true|false"]%>
<jsp:directive.page pageDirectiveAttrList />
where pageDirectiveAttrList is the same as the list in the JSP syntax.
XML Syntax
<jsp:directive.page pageDirectiveAttrList />
where pageDirectiveAttrList is the same as the list in the JSP syntax.
Examples
<%@ page import="java.util.*, java.lang.*" %> <%@ page buffer="5kb" autoFlush="false" %> <jsp:directive.page errorPage="error.jsp" />
Description
The page directive applies to an entire JSP page and any of its static include files, which together are called a translation unit. A static include file is a file whose content becomes part of the calling JSP page. The page directive does not apply to any dynamic resources; see <jsp:include> for more information.
You can use the page directive more than once in a translation unit, but you can only use each attribute, except import, once. Because the import attribute is similar to the import statement in the Java programming language, you can use a page directive with import more than once in a JSP page or translation unit.
No matter where you position the page directive in a JSP page or included files, it applies to the entire translation unit. However, it is often good programming style to place it at the top of the JSP page.
Attributes
language="java"- The scripting language used in scriptlets, declarations, and expressions in the JSP page and any included files. In v2.0, the only allowed value is
java.
- The scripting language used in scriptlets, declarations, and expressions in the JSP page and any included files. In v2.0, the only allowed value is
extends="package.class"- The fully qualified name of the superclass of the Java class this JSP page will be compiled to. Use this attribute cautiously, as it can limit the JSP container's ability to provide a specialized superclass that improves the quality of the compiled class.
- The fully qualified name of the superclass of the Java class this JSP page will be compiled to. Use this attribute cautiously, as it can limit the JSP container's ability to provide a specialized superclass that improves the quality of the compiled class.
import="{package.class|package.*}, ..."- A comma-separated list of Java packages that the JSP page should import. The packages (and their classes) are available to scriptlets, expressions, and declarations within the JSP page. If you want to import more than one package, you can specify a comma-separated list after
importor you can useimportmore than once in a JSP page.- The following packages are implicitly imported, so you don't need to specify them with the
importattribute:java.lang.*javax.servlet.*javax.servlet.jsp.*javax.servlet.http.*- You must place the
importattribute before the element that calls the imported class. - The following packages are implicitly imported, so you don't need to specify them with the
- A comma-separated list of Java packages that the JSP page should import. The packages (and their classes) are available to scriptlets, expressions, and declarations within the JSP page. If you want to import more than one package, you can specify a comma-separated list after
session="true|false"- Whether the client must join an HTTP session in order to use the JSP page. If the value is
true, thesessionobject refers to the current or new session.- If the value is
false, you cannot use thesessionobject or a<jsp:useBean>element withscope=sessionin the JSP page. Either of these usages would cause a translation-time error.- The default value is
true. - If the value is
- Whether the client must join an HTTP session in order to use the JSP page. If the value is
buffer="none|8kb|sizekb"- The buffer size in kilobytes used by the
outobject to handle output sent from the compiled JSP page to the client web browser. The default value is8kb. If you specify a buffer size, the output is buffered with at least the size you specified.
- The buffer size in kilobytes used by the
autoFlush="true|false"- Whether the buffered output should be flushed automatically when the buffer is full. If set to
true(the default value), the buffer will be flushed. If set tofalse, an exception will be raised when the buffer overflows. You cannot setautoFlushtofalsewhenbufferis set tonone.
- Whether the buffered output should be flushed automatically when the buffer is full. If set to
isThreadSafe="true|false"- Whether thread safety is implemented in the JSP page. The default value is
true, which means that the JSP container can send multiple, concurrent client requests to the JSP page. You must write code in the JSP page to synchronize the multiple client threads. If you usefalse, the JSP container sends client requests one at a time to the JSP page.
- Whether thread safety is implemented in the JSP page. The default value is
info="text"- A text string that is incorporated verbatim into the compiled JSP page. You can later retrieve the string with the
Servlet.getServletInfo()method.
- A text string that is incorporated verbatim into the compiled JSP page. You can later retrieve the string with the
errorPage="relativeURL"- A pathname to a JSP page that this JSP page sends exceptions to. If the pathname begins with a
/, the path is relative to the JSP application's document root directory and is resolved by the web server. If not, the pathname is relative to the current JSP page.
- A pathname to a JSP page that this JSP page sends exceptions to. If the pathname begins with a
isErrorPage="true|false"- Whether the JSP page displays an error page. If set to
true, you can use theexceptionobject in the JSP page. If set tofalse(the default value), you cannot use theexceptionobject in the JSP page.
- Whether the JSP page displays an error page. If set to
contentType="mimeType[; charset=characterSet]" |"text/html;charset=ISO-8859-1"- The MIME type and character encoding the JSP page uses for the response. You can use any MIME type or character set that are valid for the JSP container. The default MIME type is
text/html, and the default character set isISO-8859-1.- The MIME type and character encoding the JSP page uses for the response. You can use any MIME type or character set that are valid for the JSP container. The default MIME type is
pageEncoding="characterSet|ISO-8859-1"
isElIgnored="true |false"
- Defines whether EL expressions are ignored or evaluated for this page and translation unit. If true, EL expressions (of the form
${...}) are ignored by the container. If false, EL expressions (of the form${...}) are evaluated when they appear in template text or action attributes. The default value varies depending on the version of the Web application deployment descriptor. The default mode for JSP pages delivered using a Servlet 2.3 or earlier descriptor is to ignore EL expressions. The default mode for JSP pages delivered with a Servlet 2.4 descriptor is to evaluate EL expressions.
- Defines whether EL expressions are ignored or evaluated for this page and translation unit. If true, EL expressions (of the form
Tip
If you need to include a long list of packages or classes in more than one JSP page, you can create a separate JSP page with a page directive that contains the import list and include that file in the main JSP page.
