Java Reference
In-Depth Information
-----------------------------7d63cf13501b4
Content-Disposition: form-data; name="uid"
jeff
-----------------------------7d63cf13501b4
Content-Disposition: form-data; name="pwd"
1234
-----------------------------7d63cf13501b4
Content-Disposition: form-data; name="MAX_FILE_SIZE"
1000000
-----------------------------7d63cf13501b4
Content-Disposition: form-data; name="uploadedfile"; filename="C:\
Documents and Settings\jeff\Desktop\myfile.txt"
Content-Type: text/plain
This is the contents of myfile.txt.
-----------------------------7d63cf13501b4--
One of the first things you should notice is the boundary. The boundary is specified in
the Content-Type header. For this example, the boundary is as follows:
-----------------------------7d63cf13501b4
The boundary is used to separate each of the parts. There is one part for each control
on the HTML form. The first two fields, named uid and pwd contain the user's id and
password. These two fields have the values of “jeff” and “1234” respectively. The next field is
a hidden field, named MAX_FILE_SIZE , which specified the maximum file size that this
form will accept. In this case, it is a megabyte.
The final field, named uploadedfile , contains the file that we are uploading. The
raw binary image of the file is inserted here. For this example, I uploaded a very simple file
that contains the text, “This is the contents of myfile.txt”. You can see this string in the above
form request.
As you can see there are a number of important considerations when responding to a
form. In the next section, we will examine a class that can be used to quickly build both mul-
tipart and regular responses.
Processing Forms
All of the recipes in this chapter make use of a simple class named FormUtility .
This class allows you to quickly create form responses for both regular and multipart form
responses. The FormUtility class is shown in Listing 7.1.
Search WWH ::




Custom Search