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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.