Powered by Blogger.

Sunday 1 March 2015

Handling HTTP Requests And Responses

No comments :
The HttpServlet class provides specialization methods that handle the various types of HTTP requests. A servlet developer typically overrides one of these methods. these methods are doDelete(), doGet(), doHead(), doOptions(),doPost(), and doTrace(). the GET and POST requests are commonly used when handling form input. Handling HTTP GET Requests: Here we will develop a servlet that handles an HTTP GET 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 ColorGet.html, and a servlet is defined in ColorGetServlet.java. The HTML source code for ColorGet.html is shown in the following listing. It defines a form that contains a select element and a submit button. Notice that the action parameter of the form tag specifies a URL. The URL identifies a servlet to process the HTML GET request.

The source code for ColorGetServlet.java is shown in the following listing. the doGet() 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.