Retrieving Form Variables in a Servlet

Up to this point, the discussion has centered around the request object in Java Server Pages. In case you missed it, the request object in a JSP is an instance of HttpServletRequest. If you recall from Chapter 13, "Servlets," an HTTP servlet receives an instance of HttpServletRequest when its service method is invoked. This means, of course, that you already know how to retrieve form variables in a servlet because you do it the same way you do in a Java Server Page.

Listing 15.6 shows a servlet version of the ShowParameters Java Server Page you saw in Listing 15.5. Again, you can test it out by passing parameters directly in the URL.

Code Listing 15.6. Source Code for ShowParametersServlet.java
 package ...

Get Special Edition Using Java™ 2 Enterprise Edition 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.