|
An Overview Of Servlets
The Web-Side Helpers
Servlets are modules that extend request/response-oriented
servers, such as Java-enabled Web servers. For example, a
servlet might be responsible for taking data in an HTML order-entry
form and applying the business logic used to update a company's
order database.
Servlets are to servers what applets are to browsers. Unlike
applets, however, servlets have no graphical user interface.
Servlets can be embedded in many different servers because
the servlet API, which you use to write servlets, assumes
nothing about the server's environment or protocol. Servlets
have become most widely used within HTTP servers; many Web
servers support Java Servlet technology.
A servlet can handle multiple requests concurrently, and can
synchronise requests. This allows servlets to support systems
such as on-line conferencing.
Servlets can forward requests to other servers and servlets.
Thus servlets can be used to balance load among several servers
that mirror the same content, and to partition a single logical
service over several servers, according to task type or organisational
boundaries.
Servlets are an effective replacement for CGI scripts. They
provide a way to generate dynamic documents that is both easier
to write and faster to run. Servlets also address the problem
of doing server-side programming with platform-specific APIs:
they are developed with the Java Servlet API, a standard Java
extension.
Why are servlets better than CGI programs written in languages
such as Perl and C?
Servlets are cross-platform: Because servlets are written
in Java, they can be used on multiple platforms without worrying
about compatibility issues or recompilation.
Servlets are fast: Standard CGI programs are slow because
a new process must start up and run for every client request.
For example, if 25 users are using a Perl CGI search engine,
25 separate versions of the program have to be loaded into
memory and executed... that's a lot of overhead.
Java servlets are fast because they are persistent. The same
search engine as a servlet would load only once and then service
all 25 clients using multiple threads. It would then stay
loaded in memory and wait for more requests instead of shutting
down.
Servlets are elegant; because Java was created from the start
to be object-oriented, programs written in that language tend
be organised more effectively into easily manageable parts.
This makes servlets easier to maintain and understand.
Servlets are secure: Servlets are run in the Java security
sandbox so can be insulated from disrupting the operating
system or breaching security. Additionally, many security
holes in traditional CGI languages result from those languages
being weakly typed. Java's strong typing helps to ensure fewer
accidental security mistakes.
Many servlets resources are available around the Web. A good
place to start is on Sun's Java site, specifically, the servlet
page. Among other things, you'll find a popular mailing list
there.
|