
Directive tag ( <%@ directive …
%>)
A
JSP directive gives special information about the page to the
JSP Engine.
There
are three main types of directives:
1)
page
– processing information for this page.
2)
Include
– files to be included.
3)
Tag
library – tag library to be used in this page.
Directives
do not produce any visible output when the page is requested
but change the way the JSP Engine processes the page.
For
example, you can make session data unavailable to a page by
setting a page directive (session) to false.
1.
Page
directive
This
directive has 11 optional attributes that provide the JSP
Engine with special processing information. The following
table lists the 11 different attributes with a brief
description:
language
|
Which
language the file uses.
|
<%@ page language = “java” %>
|
extends
|
Superclass
used by the JSP engine for the translated Servlet.
|
<%@ page extends = “com.taglib…” %>
|
import
|
Import
all the classes in a java package into the current JSP
page. This allows the JSP page to use other java
classes.
|
<%@ page import = “java.util.*” %>
|
session
|
Does
the page make use of sessions. By default all JSP pages
have session data available. There are performance
benefits to switching session to false.
|
Default is set to true.
|
buffer
|
Controls
the use of buffered output for a JSP page. Default is
8kb
|
<%@ page buffer = “none” %>
|
autoFlush
|
Flush
output buffer when full.
|
<%@ page autoFlush = “true” %>
|
isThreadSafe
|
Can
the generated Servlet deal with multiple requests? If
true a new thread is started so requests are handled
simultaneously.
|
|
info
|
Developer
uses info attribute to add information/document for a
page. Typically used to add author, version, copyright
and date info.
|
<%@ page info = “builder.com test page,
copyright 2001. “ %>
|
errorPage
|
Different
page to deal with errors. Must be URL to error page.
|
<%@ page errorPage = “/error/error.jsp” %>
|
IsErrorPage
|
This
flag is set to true to make a JSP page a special Error
Page. This page has access to the implicit object
exception (see later).
|
|
contentType
|
Set
the mime type and character set of the JSP.
|
|
2.
Include
directive
Allows
a JSP developer to include contents of a file inside another.
Typically include files are used for navigation, tables,
headers and footers that are common to multiple pages.
Two
examples of using include files:
This includes the html from privacy.html found in the
include directory into the current jsp page.
<%@ include file = “include/privacy.html %>
or to include a naviagation menu (jsp file) found in the
current directory.
<%@ include file = “navigation.jsp %>
Include
files are discussed in more detail in the later sections of
this tutorial.
3.
Tag
Lib directive
A
tag lib is a collection of custom tags that can be used by the
page.
<%@
taglib uri = “tag library URI” prefix = “tag Prefix”
%>
Custom
tags were introduced in JSP 1.1 and allow JSP developers to
hide complex server side code from web designers.
|