Sun Java System Web Server 6.1 SP7 Programmer's Guide to Web Applications

About Servlets

Servlets, like applets, are reusable Java applications. Servlets, however, run on a Web Server rather than in a Web Browser.

Servlets provide a component-based, platform-independent method for building web-based applications, without the performance overheads, process limitations, and platform-specific liabilities of CGI programs.

Servlets supported by the Sun Java System Web Server are based on the Java Servlet 2.3 specification.

The following list describes the fundamental characteristics of servlets.

Servlets:

This section includes the following topics:

Servlet Data Flow

When a user clicks a Submit button, information entered in a display page is sent to a servlet. The servlet processes the incoming data and orchestrates a response by generating content. Once the content is generated, the servlet creates a response page, usually by forwarding the content to a JSP. The response is sent back to the client, which sets up the next user interaction.

The following illustration shows the information flow to and from the servlet.

ProcedureTo show the servlet data flow

  1. The servlet processes the client request.

  2. The servlet generates content.

  3. The servlet creates a response and either:

    1. Sends it back directly to the client

      - or -

    2. Dispatches the task to a JSP

      The servlet remains in memory, available to process another request.

      Figure 2–1 Servlet Data Flow Steps

      Servlet Data Flow Steps

Servlet Types

There are two main servlet types, generic and HTTP: