The HTTP Programming Model
HTTP is a request-response application protocol. When programming with Java HTTP libraries, such as the Generic Connection Framework, the parameters of the request must always be set before the request is sent. This allows the entire request, including parameters, to be sent at the same time.
Request Methods
There are two commands to send data from a form on a web page to a
CGI script or a servlet hosted by the HTTP server. These commands are
GET and POST. Each of these has
a different way of sending data to the server.
For the
GETmethod, the input values are sent as part of the URL in theQUERY_STRINGenvironment variable.For the
POSTmethod, data is sent as an input stream and its length is saved in theCONTENT_LENGTHenvironment variable.
The POST method is more secure, and you can send
more data using it. As an example, consider the following HTML code
for the form shown in Figure 7-3.

Figure 7-3. Form with one field (GET method)
<form action=http://www.somesite.com/cgi-bin/getgrade.cgimethod="GET">
Student#:
<input type="text" name="idnum" size=30>
<input name="RetrieveMarks" value="Retrieve Marks" type="submit">
</form>This form is handled by the script at
http://www.somesite.com/cgi-bin/getgrade.cgi.
Note that the form uses the GET method to transmit the information. When the user enters a student number, such as 112233, and clicks the Retrieve ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access