Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (596.04 KB, 2 trang )
Chapter 5. Generating Dynamic Content
53
Figure 5-1. JSP book examples main page
Figure 5-2. The "JSP is Easy" example output
The page shown in Example 5-1 contains both regular HTML elements and JSP elements. If
you use the View Source function in your browser, you notice that none of the JSP elements
are visible in the page source. That's because the server processes the JSP elements when the
page is requested, and only the resulting output is sent to the browser. The HTML elements,
on the other hand, are sent to the browser as-is, defining the layout of the page. To see the
unprocessed JSP page in a separate window, you can click on the source link for the easy.jsp
file in the book example's main page. The source link uses a special servlet to send the
unprocessed JSP page directly to the browser instead of letting the server process it. This
makes it easier for you to compare the source page and the processed result.
5.4 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
Chapter 5. Generating Dynamic Content
54
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