A Basic Servlet

In this section, we are going to look at building and running a very basic servlet. Its purpose will be to service a request and respond with the request method used by the client. We will take a quick look at the servlet's source code, the steps involved in compiling and installing the servlet, and the HTML necessary to invoke the servlet.

The BasicServlet Source

Listing 2.1 contains the source code for this example. You can find the following source listing on this book's Web site. If you have the time, it is probably best if you type the first few examples yourself. This will help you become familiar with the basic parts of servlets.

Code Listing 2.1. BasicServlet.java Displays the Request Method Used by the Client
 import ...

Get Pure Java Server Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.