3.4. Example: Reading All Parameters

The previous example extracted parameter values from the form data based upon prespecified parameter names. It also assumed that each parameter had exactly one value. Here's an example that looks up all the parameter names that are sent and puts their values in a table. It highlights parameters that have missing values as well as ones that have multiple values.

First, the servlet looks up all the parameter names by the getParameterNames method of HttpServletRequest. This method returns an Enumeration that contains the parameter names in an unspecified order. Next, the servlet loops down the Enumeration in the standard manner, using hasMoreElements to determine when to stop and using nextElement to get each ...

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.