Extracting Request Information

The Web is certainly a more interesting place when we can interact with it, and that means telling a Web site just what we want. Normally, this is done through forms, which we'll cover in Chapter 5, but we're going to get a small taste of it now.

We want to be able to have our servlet display a single product page requested by the user, so we have to have a way to know which product page the user wants. One way to do that is to embed information directly into the URL.

Before we go back to TransformProd, let's take a look at extracting that information using HelloWorldServlet. Add the information shown in Listing 4.31 and recompile.

Listing 4.31. Extracting Information from the URL
 0:import java.io.*; 1:import javax.servlet.*; ...

Get XML and Java™ from scratch 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.