The page
directive defines one or more attributes for the entire JSP page.
A JSP page can contain multiple page
directives; however with the exception of the import
attribute, you can only reference an attribute once. That is, if you specify multiple page
directives with conflicting attributes, the first instance of the page
directive in the JSP page is recognized, and subsequent attempts to redefine the attribute are ignored.
You can specify multiple page
directives containing the import
attribute. All files referenced by the import
attribute are imported.
The syntax for the page directive is as follows:
<%@
page attribute = "value" ...%>
where:
attribute
= language | import | contentType | session | buffer | autoflush | isThreadSafe | info | errorPage | isErrorpage | extends
value
= a string literal in single or double quotes.
A page directive containing any other attribute causes an exception.
For example, the following directive sets the output MIME type of a JSP page to HTML and the scripting language to JavaScript:
<%@ page contentType
= "text/html" language = "javascript" %>
Defines the scripting language used in the file. If you omit this attribute, the default scripting language is java
(for the Java programming language).
Acceptable values include: java
, javascript
, and webl
.
Specifies a comma-delimited list of packages that the compiled page will need to import for use. For example:
<%@ page import
= "java.io.*,java.util.Hashtable" %>
If the language of the JSP page is Java, the default import file list is:
A default import list does not exist for languages other than Java. You must import the necessary files for your scripting language if you do not use Java, or if you use Java and require a different set of imported files.
Defines the MIME type and, optionally, character set of the response generated by the JSP page. By default, the MIME type is text/html and the character set is ISO-8859-1. When this attribute is used more than once, only the first attribute is significant.
The syntax of this attribute is shown below:
<%@ page contentType
= "TYPE; charset = CHARSET" %>
TYPE specifies the output MIME type and CHARSET optionally specifies the character set as an Internet Assigned Numbers Authority (IANA) value.
See the following URL for a list of possible MIME types:
ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/media-types
You can see a list of the supported character encodings for CHARSET at the following URL:
http://java.sun.com/products/jdk/1.1/docs/guide/intl/
encoding.doc.html
Following is an example of contentType
that sets the output type to plain text:
page contentType
= "text/plain" %>
Specifies that the page is accessed as part of a session.
A value of "true"
specifies that the JSP object session
is initialized to the current session for the page.
A value of "false"
specifies that the page is not part of session and that the session
object is unavailable. Any reference to session
within the body of the JSP page results in a fatal translation error.
The default value is "true"
.
Specifies the buffering model for the page output.
A value of "none"
specifies that there is no buffering, and all page output is written directly to the client.
If you specify a buffer size, the output is buffered with a buffer size not less than that specified. Depending on the value of the autoFlush
attribute, either the contents of the buffer are automatically flushed, or an exception is raised when an overflow would occur.
The default value of this attribute is buffered with a buffer size of 8kb.
Specifies whether the buffered output should be flushed automatically (value equals "true"
) when the buffer is filled, or that an exception is raised (value equals "false"
) to indicate buffer overflow.
The default value is "true"
. Note that you cannot set autoFlush
to "false"
when buffer
equals "none"
.
Specifies the level of thread safety implemented by the page.
If you set this attribute to "false"
, JRun creates multiple instances of the page to handle multiple requests, and each page instance has a single thread.
If you set this attribute to "true"
, JRun may choose to dispatch multiple outstanding client requests to the page simultaneously. If you specify "true"
you ensure that your JSP page properly synchronizes access to the page's shared state.
The default value is "true".
Specifies a string incorporated into the JSP page that can be obtained at run time. An application can access this string using the getServletInfo()
method for the Servlet
object representing this servlet.
Specifies that the JSP page handles uncaught exceptions from another JSP page.
A value of "true"
specifies that the JSP exception
object is defined, and its value is set to the exception from the source JSP page when the JSP page is invoked.
A value of "false"
specifies that the exception
object is unavailable, and any reference to it within the body of the JSP page results in a fatal translation error.
The default value is "false".
Specifies a URL to a JSP page to which any exceptions not caught by the page are forwarded for error processing. The destination JSP page must comply with the Version 1.1 JSP specification.
The destination page must use the page
directive to set the isErrorPage
attribute to "true"
.
When invoked, the destination JSP page's exception
object contains a reference to the exception.
Note | If you set autoFlush to true, and if any output data from the page
throwing the exception has been flushed, then an attempt to pass
the exception to an error page may fail.
|
Specifies a Java base class that the JSP subclasses. For example:
<%@ page extends
= "com.myPackage.AServletImplementation" %>
By default, JRun creates servlets as a subclass of the class
javax.servlet.http.HttpServlet
. Therefore, you should not use this attribute
unless you have a specific reason for defining the base class of the servlet.