Java Reference
In-Depth Information
Chapter 9
JavaServer Pages (JSPs)
Learning Objectives
After reading this chapter, you should:
￿
appreciate why the JavaServer Pages technology was introduced and the circum-
stances under which JSPs should be used instead of servlets;
￿
appreciate when JSPs and servlets may appropriately be used together;
￿
be aware of the process that occurs when a JSP is referenced by a browser;
￿
know the basic structure and allowable contents of a JSP;
￿
know how to combine the above elements to produce a working JSP;
￿
know how to combine JSPs and servlets in an application;
￿
know how to set up a JSP error page to handle exceptions generated by a JSP.
The term JavaServer Pages is used to refer to both a technology and the individual
software entities created by that technology (though reference is often made, some-
what redundantly, to 'JSP Pages', rather than simply JSPs). The technology was
introduced in late 1999 as a new Java API and is an extension of servlet technology.
Like servlets, JSPs (the software entities) generate HTML pages with dynamic con-
tent. Unlike servlets, though, JSPs are not Java programs, but HTML documents
with embedded Java code supplied via HTML-style tags. A JSP fi le must have the
suffi x .jsp , which will allow the JSP to be recognised by any JSP-aware Web server,
so that the JSP fi lename may be supplied in a URL to a browser or may appear in
the address for a hyperlink on an HTML page (as, indeed, may any servlet). We can
use Tomcat to test our JSPs, just as we used it to test our servlets.
9.1
The Rationale Behind JSPs
Since JSPs serve essentially the same purpose as servlets, it is natural to ask why
there is a need for both. The simple answer is that servlets require the expertise of
Java programmers, whilst the production of Web pages for anything more than a
Search WWH ::




Custom Search