The JavaTM Tutorial
Previous Page Trail Contents Next Page Start of Tutorial Search

Trail: Servlets

by Cynthia Bloch

The Servlets trail teaches you about servlets, the bodies of code that run inside servers, and extend their functionality. For example, servlets offer an efficient platform-independent replacement for CGI scripts. Servers that can host servlets are Java-enabled servers that respond to client requests.

Your feedback is important to us! If you have comments about this trail, send them to: In your message, put servlets in the subject header.

Overview of Servlets tells you what servlets are, and how you can use them. The lesson also introduces the example servlets used in this trail.

Client Interaction shows you how to write servlets that interact with clients. The servlets in this lesson respond to HTTP GET, HEAD and POST requests. The lesson also discusses threading issues, and shows you how to avoid problems by creating a servlet that responds to one client at a time.

The Life Cycle of a Servlet discusses the significant events in the life of a servlet and shows you how to customize servlet initialization and shutdown.

Saving Client State shows you how to use session tracking and cookies.

Servlet Communication shows you how to have your servlet communicate with other servlets and other resources, such as CGI scripts.

Utilities for Running Servlets describes how to test your servlets with a utility called servletrunner in version 2.0 of the Servlet API and a servlet-running server in version 2.1. These utilities come with their respective Servlet Development Kits, and are part of the servlet extension to the Java Development Kit.

Running Servlets shows you how to call servlets from a browser and within an HTML page.

Note:  The servlet API is a standard extension to the Java Development Kit. The following lessons apply to both version 2.0 and 2.1 of the Java Servlet Development Kit (JSDK). Sections that pertain to only one version of the JSDK are clearly marked. You can download the Servlet Development Kit from

Previous Page Trail Contents Next Page Start of Tutorial Search