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.
There are three different JSP directives: page,
include, and taglib. In this
chapter, we’re using the page and
the taglib directives. The
include directive is described in Chapter 16.
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 for HTML content and
text/plain for preformatted, plain text. But you can also ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access