O'Reilly logo

XML and Java™ from scratch by Nicholas Chase

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.*; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required