Java Reference
In-Depth Information
9.3.1
Directives
There are three tags in this category:
page
(used to defi ne the attributes of the Web page, via a number of other key-
words such as
language
,
contentType
and
import
);
include
(specifying an external fi le to be inserted);
taglib
(specifying a custom tag library to be used).
These directives are processed by the JSP engine upon conversion of the JSP into
a servlet. Such tags commence with
<%@
and end with
%>
. Note there must be
no
spaces
between
%
and
@
!
Examples
<%@ page language="java" contentType="text/html"
import="java.util.*" %>
(The
language
and
contentType
settings above are actually super-
fl uous, since they are the default values.)
<%@ include fi le="myFile.html" %>
<%@ taglib uri="myTagLib" %>
Note the use of the
import
attribute with the
page
tag to allow the usual abbre-
viated reference to the contents of any available Java package.
9.3.2
Declarations
These declare variables for subsequent use in expressions or scriptlets. (See below.)
The tags commence with
<%!
and end with
%>
.
Examples
<%! int visitCount; %>
<%! Date today = new Date(); %>
Such declarations refer to instance variables of the servlet class that will be created
from this JSP and will be recognised within any subsequent JSP tags on the page.
9.3.3
Expressions
These tags are used to specify Java expressions, the values of which will be cal-
culated and inserted into the current page. Such an expression can involve any
valid combination of literals, variables, operators and/or method calls that returns
Search WWH ::
Custom Search