Reading Servlet Parameters Java Help

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 Servlet.java 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.

JavaHelpOnline.com

  • Feel free to send us an inquiry, we will reply back in hours.
 

Verification

Posted on September 18, 2014 in Servlets

Share the Story

About the Author

Back to Top