Get Request Parameters in a Servlet

This example shows how to get the parameters sent in a http request to a servlet. In this example we use the method service() which will process requests of type GET as well as requests of type POST.
To get the parameter names the method getParameterNames() is called on the request object. The method returns an Enumeration which we use to loop through the parameter names, and for each name the method getParameter() is called on the request object to get the value of that parameter.

So, if the http request looked like this in the browser (assuming we run the servlet on our own computer):

The output to the page would be:

Search for more Java info on this site here:
Custom Search

One thought on “Get Request Parameters in a Servlet

Please type any questions here.