Java Reference
In-Depth Information
If the boundary variable was null , meaning this is not a multipart response, then we
must check to see if this is the first name-value pair. If it is not the first name-value pair, then
an ampersand should be appended.
} else
{
if (!first)
write("&");
Next, we encode both the name and value. The name and value are written, separated by
an equal sign.
write(encode(name));
write("=");
write(encode(value));
}
Now that we have completed the first name-value pair, we can set the first variable
to false.
first = false;
The name-value pair has now been completed. The add method can be called again to
add another name-value pair.
Add a File
Name-value pairs are not the only data that you may respond to a form with. If this is a
multipart response, then you can also respond with files. There is an overloaded version of
the add method that accepts a “File” object.
First, the add method makes sure that this is a multipart response. If this is a multipart
response, then the boundary variable will not be null . If you call the file version of add on
a non-multipart response, the method call will be ignored.
if (boundary != null)
{
First, a boundary line is written. Next, the field name is written followed by the filename.
To see exactly what this line looks like when written out, refer to the section, earlier in this
chapter, about the multipart POST .
boundary();
writeName(name);
write("; filename=\"");
write(file.getName());
write("\"");
newline();
Search WWH ::




Custom Search