Java Reference
In-Depth Information
a Post request is created and sent, not a Get request. A Post request contains the form information and, like a Get
request, asks the server for a particular resource. The resource in a Post request can be a servlet.
Just to be perfectly clear: there are two types of requests, Gets and Posts. Get requests are browser requests for a
particular Web resource (e.g., Web page, servlet). Post requests also request a resource (e.g., Web page, servlet) but,
in addition, contain the form information. A Post request (with the form information) is created and sent when a form
submit button is clicked.
Figure 8-13 shows (1) the user supplying a URL to the browser. (The URL could have been entered in the
browser's address field or be specified in a form.) The browser creates a request and, based on the URL, sends it to the
correct server (2).
Figure 8-13.
If the request is for a Web page, the server retrieves the HTML file from secondary storage (step 3 in Figure 8-14 ).
The server then creates a response and embeds the web page (i.e., the HTML) along with communication information
needed to route the response back to the browser (4). The server sends the response (5). The browser receives the
response, retrieves the HTML from the response, and displays the Web page to the user (6).
Figure 8-14.
If, instead, the request is for a servlet, the server creates a response object but does not embed any HTML
(see step 3 in Figure 8-15 ). The servlet class file is retrieved from storage, and an object of that class type is instantiated (4).
Then either the servlet's doGet or doPost method is executed. (Can you guess what decides which method is executed?
Yes, if the browser's request was a Get, the servlet's doGet method is invoked. If the request was a Post, the servlet's
doPost method is executed.) The Server passes both the request (actually a HTTPServletRequest ) object and the just
created response ( HTTPServletResponse ) object to the doPost or doGet methods (5).
 
Search WWH ::




Custom Search