The JavaTM Tutorial

| Start of Tutorial > Start of Trail | Search Feedback Form

Trail: Servlets

## Lesson: Overview of Servlets

> 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 the Servlet API.

> ## Use Servlets instead of CGI Scripts!

> 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.

> So use servlets to handle HTTP client requests. For example, have servlets process data POSTed over HTTPS using an HTML form, including purchase order or credit card data. A servlet like this could be part of an order-entry and processing system, working with product and inventory databases, and perhaps an on-line payment system.

> ## Other Uses for Servlets

> Here are a few more of the many applications for servlets:

> - Allowing collaboration between people. A servlet can handle multiple requests concurrently, and can synchronize requests. This allows servlets to support systems such as on-line conferencing.
> - Forwarding requests. 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 organizational boundaries.

> ## Get Ready to Write

> To prepare you to write servlets, this lesson discusses:

### Architecture of the Servlet Package

> Discusses the purposes of the main interfaces and objects in the Servlet package.

### A Simple Servlet

> Shows you what the code for a very simple servlet looks like.

### The Trail's Servlets

> Tells you about the example used in the rest of this trail.

| Start of Tutorial > Start of Trail | Search Feedback Form