Java Reference
In-Depth Information
*
* @param str
* The string to write.
* @throws IOException
* If any error occurs while writing.
*/
protected void writeln(String str) throws IOException
{
write(str);
newline();
}
}
The next few sections will demonstrate how the
FormUtility
class was construct-
ed. If you are only interested in using the
FormUtility
class, and not with how it works
internally, you can safely skip to the recipes.
There are three main features of the
FormUtility
class.
• Add a name-value pair
• Add a file
• Parse a query string
The next three sections will show how each of these features are implemented.
Add a Name-Value Pair
Adding a name-value pair is a very common operation performed for a form. Every form
control results in a name-value pair. Adding a name-value pair is accomplished by calling the
add
method.
The format for a name-value pair is very different when posting using a multipart form
compared to a regular form. Therefore, the first thing that the
add
method does, is to de-
termine if this is a multipart response. If the boundary variable is not
null
, then this is a
multipart request.
if (boundary != null)
{
Next, the boundary and name are written.
boundary();
writeName(name);
newline();
newline();
writeln(value);