Chapter 7. Using JSP: Being a JSP

image with no caption

A JSP becomes a servlet. A servlet that you don’t create. The Container looks at your JSP, translates it into Java source code, and compiles it into a full-fledged Java servlet class. But you’ve got to know what happens when the code you write in the JSP is turned into Java code. You can write Java code in your JSP, but should you? And if you don’t write Java code, then what do you write? How does it translate into Java code? In this chapter, we’ll look at six different kinds of JSP elements—each with its own purpose and, yes, unique syntax. You’ll learn how, why, and what to write in your JSP. Perhaps more importantly, you’ll learn what not to write in your JSP.

OBJECTIVES

The JSP Technology Model

6.1

Identify, describe, or write JSP code for the following elements: (a) template text, (b) scripting elements (comments, directives, declarations, scriptlets, and expressions), (c) standard and custom actions, and (d) expression language elements.

6.2

Write JSP code that uses the directives: (a) page (with attributes import, session, contentType, and isELIgnored), (b) include, and (c) taglib.

6.3

Write a JSP Document (XML-based document) that uses the correct syntax.

6.4

Describe the purpose and event sequence of the JSP page lifecycle: (1) JSP page translation, (2) JSP page compilation, (3) load class, (4) create instance, (5) call the jspInit method, (6) call the _jspService method, and (7) call the jspDestroy method.

6.5

Given a design goal, write JSP code using the appropriate implicit objects: (a) request, (b) response, (c) out, (d) session, (e) config, (f) application, (g) page, (h) pageContext, and (i) exception.

6.6

Configure the deployment descriptor to declare one or more tag libraries, deactivate the evaluation language, and deactivate the scripting language.

6.7

Given a specific design goal for including a JSP segment in another page, write the JSP code that uses the most appropriate inclusion mechanism (the include directive or the jsp:include standard action).

Coverage Notes:

Most is covered in this chapter, but the details behind (c) standard and custom actions, and (d) expression language elements are covered in later chapters.

The page directive is covered in this chapter, but include and taglib are covered in later chapters.

Not covered here; refer to the chapter on Deployment.

All covered in this chapter, although you’re expected to already know what most of them mean based on the previous two chapters.

All covered in this chapter. (Hint: these will be some of the most no-brainer questions on the real exam, once you’ve learned the fundamentals in this chapter.)

We cover everything here except declaring tag libraries. That’s covered in the chapter on Using JSTL.

Not covered here; refer to the next chapter (Scriptless JSPs).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset