Java Reference
In-Depth Information
CHAPTER 18
Servlets and JSP
A servlet is a Java class that implements the javax.servlet.Servlet interface, or,
more commonly, extends the abstract javax.servlet.http.HttpServlet class.
Servlets, and the Java Servlet API, are an extension architecture for web servers. *
Instead of serving only static web pages, a servlet-enabled web server can invoke
servlet methods to dynamically generate content at runtime. This model offers a
number of advantages over traditional CGI scripts. Notably, servlet instances can
persist across client requests, so the server is not constantly spawning external
processes.
JSP stands for JavaServer Pages; it is an architecture built on top of the Servlet API.
A JSP page contains HTML output intermingled with Java source code, special JSP
tags, and tags from imported “tag libraries.” A JSP-enabled web server compiles
JSP pages on the fly, turning JSP source into servlets that produce dynamic output.
This chapter includes examples of both servlets and JSP pages and concludes with
an example that shows how servlets and JSP pages can be integrated into an easy-
to-deploy web application. It begins, however, by describing the prerequisites for
compiling, deploying, running, and serving servlets. For more detailed information
about servlets, see O'Reilly & Associates' Java Servlet Programming , by Jason
Hunter with William Crawford. O'Reilly also has a forthcoming topic, JavaServer
Pages , by Hans Bersten, that will provide much more detail than is possible in this
chapter.
Servlet Setup
In order to run the examples in this chapter, you need the following:
* The javax.servlet package can actually be used with any type of server that implements a request/
response protocol. Web servers are currently the only common usage of servlets, however, and this
chapter discusses servlets in that context only.
Search WWH ::




Custom Search