Using JSP Directive Elements
Let’s look at each piece of Example 5-1 in detail. The first two lines are JSP
directive
elements.
Directive elements specify attributes of the page itself, such as the
type of content produced by the page, page-buffering requirements,
declaration of other resources used by the page, and how possible
runtime errors should be handled. Hence, a directive
doesn’t directly affect the content of the response
sent to the browser, but it tells the container how it should handle
the page. There are three different directives that you can use in a
JSP page: page
, include
, and
taglib
. In this chapter, we’re
using the page
and the taglib
directives. The include
directive is described in
Chapter 17.
JSP pages typically starts with a
page
directive that specifies the content
type for the page:
<%@ page contentType="text/html" %>
A JSP directive element starts with a directive-start identifier
(<%@
), followed by the directive name
(page
in this case), directive attributes, and
ends with %>
. A directive contains one or more
attribute name/value pairs (e.g.,
contentType="text/html
“). Note that JSP element
and attribute names are case-sensitive, and in most cases, the same
is true for attribute values. All attribute values must also be
enclosed in single or double quotes.
The page
directive has many possible attributes. In Example 5-1, only the contentType
attribute is used. It specifies the MIME-type for the content the
page produces. The most common values are
text/html ...
Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.