Handling HTTP POST Requests Java Help

Handling HTTP POST Requests
This section develops a servlet that handles an HTIP POST request. The scrvlet is invoked when a form on a Web page is submitted. The example contains two files:

ColorPost.htm defines a Web page and ColorPos Servlet java defines a servlet, The HTML source code for ColorPost.htm is shown in the following listing.,It is identical to ColorGet.htm except that the method parameter for the form tag explicitly specifies that the POST method should be used, and the action parameter for the form tag specifies a different servlet. THe source code (or ColorPostServlet.java is shown in the following listing. The doPost( ) method is overridden to process any HlTP POST requests that are sent to this servlet. It uses the getParameter( ) method of HttpServletRequest to obtain the selection that was made by the user. A response is then formulated Compile the servlet and then test it by performing the same steps described in the previous section

Note that parameters for an HITP POST request are not included as part of the

URL that is sent to the Web server. In this example, the URL sent from the browser to the server is the following:

http; 1/ localhost: uoao I~crvler IColorGetScrvlet

The parameter names And Values arc sent in the body of the HTTP request.

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
Share This