Section A.2. Directives

   

A.2 Directives

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 .

A.2.1 The include Directive

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.


Table A.1. include Directive Attributes

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.

A.2.2 The page Directive

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.*' %> 
Table A.2. page Directive Attributes

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.

A.2.3 The taglib Directive

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


Java for ColdFusion Developers
Java for ColdFusion Developers
ISBN: 0130461806
EAN: 2147483647
Year: 2005
Pages: 206
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net