4.2. Printing All Headers

Listing 4.1 shows a servlet that simply creates a table of all the headers it receives, along with their associated values. It also prints out the three components of the main request line (method, URI, and protocol). Figures 4-1 and 4-2 show typical results with Netscape and Internet Explorer.

Figure 4-1. Request headers sent by Netscape 4.7 on Windows 98.

Figure 4-2. Request headers sent by Internet Explorer 5 on Windows 98.

Listing 4.1. ShowRequestHeaders.java
 package coreservlets; import java.io.*; import javax.servlet.*; ...

Get Core Servlets and JavaServer 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.