Handling ‘HTTP Requests and .Responses
The Hup servtet class provides specialized methods that handle the various types of requests. 1\ servlet developer typically overrides one of these methods. These methods arc doDeka( ) duct( ). do Options( ), do Post(), foldout( ), and racetrack( ). A. complete dcscripion of the different types of HTTP requests is beyond the scope of this hook. However, the GET and POST methods are commonly used when handling form input. Therefore, this section prcs~nts examples of these cases You may learn more about HTTP by consulting RFC 2068 at the Internet Engineering Task Force site (http://www.ietE.org).
The source code for Color Get Servlet java is shown in the following listing, The doGeT) method is overridden to process any I·m’p GET requests that arc sent to this servlet.IS uses the getParameter() method of HttpSerVletRequest to obtain the selection that Will> made by the user. t.response is then formulated. Compile the servlet and then perform these steps to test this example:
1. Start the nervelessness.
2. Display the Web page in a browser.
3. Select a color.
4. Submit the Web page.
After completing these steps, the browser displays the response that is dynamically generated, by the servlet One other point: Paramets for an HTTP GET request are included as part of the URL that is sent to the Web server. Assume that the user selects the red option and submits the form. The URL sent from the browser to the server is the following:
The characters to the right of the question mark are known as the query string.