JSP directives send instructions to the JSP container regarding page properties, tag libraries, and include files. Directives are specified with this opening JSP tag: <%@. There are three directives for use within a JSP: include , page , and taglib .
The include directive allows you to include a separate text file within the current page. The include directive processes any JSP within the included file at run time. This manner of processing is distinct from the jsp:include action.
The include directive has one attribute: file , which indicates the file to be included.
Usage:
<%@ include file='header.jsp' @%>
Note
In JSP, you use the include directive when you would use the ColdFusion tag <cfinclude template = "header.cfm"> in ColdFusion.
Attribute | Description | Notes |
---|---|---|
file | File location | (required) Specifies the file to be included. The root directory is the root of the page's application. |
The implication of the include directive processing the included file content when it does is that inserted variables reside in the local page scope; all code is included as if it had originally been written directly in the calling template.
The page directive specifies attributes for the page and how it should load. You may have one or more page attributes within a given template. All attributes are optional. Default values are specified for many of the attributes.
Usage:
<%@ page language = 'java' session = 'true' import = 'java.util.*' %>
Attributes | Description | Notes |
---|---|---|
autoFlush | Toggles the buffer flush | Boolean value determines whether the buffer will be automatically flushed or flushed via programmatic control. Default is true. |
buffer | Buffer size in kB | Defines buffer size in format 16 kB. Default is 16 kB. |
contentType | Page MIME type | MIME type and character set of the page to use in response. Default is text/html; charset=ISO-8859-1. |
errorPage | Error page to use | Defines relative URL to forward processing to if an error occurs. |
extends | Class the page extends | States the Java class this JSP extends. |
import | Packages to import | Allows you to import Java packages, which are separated by commas. |
info | Page information | Allows you to set information about the page that can be retrieved with the getServletInfo() method. |
isErrorpage | Error page flag | Set this value to true if the current page is an error page so that it has access to the Exception object. Default is false. |
isThreadSafe | Threads | Define how the current JSP handles threads. If true, the page handles all requests with a single instance to maintain session information. Default is true. |
language | Script language | Specifies which scripting language the page uses. Possible values are Java or JavaScript. Default is Java. |
session | Session management | Specifies whether the page can access session information. Default is true. |
The taglib directive defines a library namespace for the page. It maps the URI of the tag library descriptor to a prefix that can be used to reference tags from that library within the page.
The taglib directive has two attributes: url and prefix . The url attribute specifies the location of the tag library descriptor, and the prefix attribute specifies the prefix the custom actions use.
Usage:
<%@ taglib uri='javaforcftags' prefix='javaforcf' %>
Top |