Reading Servlet Parameters
The ServletRequest class includes methods that allow you to read the names and values of parameters that arc included in a client ,request. We will develop a servlet that illustrates their use. The example contains two files: Post Parameters.htm defines a Web page, and Post Parameters defines a servlet. The HTML source code for Post Parameters.htm is shown in the following listing. It defines a table that contains two labels and two text fields. One of the labels is Employee and the other is Phone. The form also includes  submit button. Notice that the action parameter of the form tag specifies a URL. The URL identifies the servlet to process the HTTP POST request.

The source code for Post  Parameters Servlet .java is shown in the following listing. The “service( ) method is overridden to process client requests. The getParameterNames( ) method returns an enumeration of the parameter names. These are processed in a loop. You can see that the parameter name and value arc output to the client The parameter  value is obtained via the getParameter( ) method Compile the servlet and perform these steps to test this example:

1. Start the servletrunner.

2. Display the Web page in a browser.
3. Enter an emplOyee name and phone number .in the text fields.
4. Submit the web page. .
After following these steps, the browser displays a response that is dynamically generated by the servlet.

[vfb id=1]

Share This