Java Servlets - Focus on Encapsulation and Extension of CGI

John M. Thompson


The Web Server - Servlet Container Communication Model

Web Applications are hosted by a cooperating Web Server and Servlet Container (aka Servlet Engine) fielding HTTP-based requests and invoking Servlets for processing.

The Web Server and Servlet Container are configured upon installation to communicate. For example, an Apache LoadModule statement is used to load a socket-based connector in the Apache web server.

Both processes must be running, perhaps on different machines, to support the Web App.

The role of the Web App is to handle requests to specific URLs and generate appropriate responses.

Using Servlets, a Web App has full use of one or more JVMs along with any of the J2EE Technologies - JDBC, EJB, JavaMail, etc.

Distributing Web Apps across multiple contexts can offer scaling advantages. But, the cost is increased complexity and hassle in handling individual users' session data and Web App state.


The Servlet Packages - javax.servlet and javax.servlet.http

Here is a subset of the interfaces, classes, and methods more frequently used -

Package javax.servlet contains important interfaces and classes for web application management.

Package javax.servlet.http contains additional important interfaces and classes for use in web apps.


Base Class for all HTTP Servlets - HttpServlet

Extends javax.servlet.GenericServlet.

Selected HttpServlet HTTP Request-handling (service) methods:


Service Method Parameters - Request and Response Objects

Selected HttpServletRequest methods:

Selected HttpServletResponse methods:


Session Management - Class HttpSession

Selected HttpSession methods:


A Working Example

As an example, we'll do a code walkthrough on the goAskem servlet that fields assessment delivery requests -




Originals are accessible from

Copyright 2001
by John M. Thompson
Boulder, Colorado USA
A limited right to copy this page for
individual (non-commercial)
educational use only
is hereby granted.