Powered by Blogger.

Tuesday 3 March 2015

HTTP POST Request Handling

No comments :
Here we will develop a servlet that handles an HTTP POST request. The servlet is invoked when a form on a web page is submitted. the example contains two files.
A web page is defined in ColorPost.html, and a servlet is defined in ColorPostServlet.java The HTML source code for ColorPost.html is shown is the following listing. It is identical to ColorGet.html except that the method parameter for the form tag explicitly specifies that the POST method should be used, the action parameter for the form tag specifies a different servlet.



The source code for ColorPostServlet.java is shown in the following listing. the doPost() method is overridden to process any HTTP GET 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, Next, copy it to the appropriate directory,and update the web.xml file, as previously described. then, perform these steps to text this example.
1. Start Tomcat (if is not already running).
2. Display the web page in a browser.
3. Enter an Employee name and Phone Number in the text field.
4. Submit the web page.
After following these steps, the browser will display a response that is dynamically generated by the servlet.

No comments :

Post a Comment

Please Write a Message for Programming or something Related issues.