Learn Java for Web Development

(Tina Meador) #1
CHAPTER 2: Building Web Applications Using Servlets and JSP 75

JSP Basics

This section will cover the fundamental JSP constructs. A sound understanding of the classic
approach is essential for understanding its limitations and to appreciate the power of more advanced
techniques such as Expression Language, which is a subject of the next chapter. Before Expression
Language was added to the JSP specification, a billion JSP pages were written using the classic
approach, and you may still have to maintain them or refactor them. This need for backward
compatibility is one reason why the JSP specification still covers the classic components. But when
you have to write new JSPs in your application, you should not write backward-compatible code;
instead, you should use the best-practice approach, which will be explained in the next chapter.
When JSP 1.0 was added to the JSP specification in 1999, it was meant to produce dynamic,
web-based content by embedding business-logic code in the template data. To that end, the
following JSP elements were provided to be used within a JSP page to manipulate Java objects and
perform operations upon them, thereby enabling the generation of dynamic content:


   Directives
 Declarations
 Expressions
 Scriptlets
 Implicit objects
 Standard actions

Figure 2-25. Accessing the JSP

Free download pdf