2.2. A Simple Servlet Generating Plain Text

Listing 2.2 shows a simple servlet that just generates plain text, with the output shown in Figure 2-1. Section 2.3 (A Servlet That Generates HTML) shows the more usual case where HTML is generated. However, before moving on, it is worth spending some time going through the process of installing, compiling, and running this simple servlet. You'll find this a bit tedious the first time you try it. Be patient; since the process is the same each time, you'll quickly get used to it, especially if you partially automate the process by means of a script file such as that presented in the following section.

Figure 2-1. Result of Listing 2.2 (HelloWorld.java).
Listing 2.2. HelloWorld.java
 import java.io.*; ...

Get Core Servlets and JavaServer Pages™ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.