Java Reference
In-Depth Information
All of the recipes in this chapter will make use of the form processing class that was de-
scribed in the first part of this chapter. We will begin with the first recipe, which shows you
how to process an HTTP GET .
Recipe #7.1: Using HTTP GET Forms
The first recipe shows how to access a web site and search. The form allows the user to
search the US states and capitals. You can see this page at the following URL:
http://www.httprecipes.com/1/7/get.php
This page displays a simple form that allows the user to enter a search string and choose
if they are searching states or capitals. You can see this recipe in Listing 7.2.
Listing 7.2: Using HTTP GET (FormGet.java)
package com.heatonresearch.httprecipes.ch7.recipe1;
import java.io.*;
import java.net.*;
import com.heatonresearch.httprecipes.html.*;
public class FormGET
{
/**
* Advance to the specified HTML tag.
* @param parse The HTML parse object to use.
* @param tag The HTML tag.
* @param count How many tags like this to find.
* @return True if found, false otherwise.
* @throws IOException If an exception occurs while reading.
*/
private boolean advance(ParseHTML parse, String tag, int count)
throws IOException
{
int ch;
while ((ch = parse.read()) != -1)
{
if (ch == 0)
{
if (parse.getTag().getName().equalsIgnoreCase(tag))
{
count--;
if (count <= 0)
return true;
}
Search WWH ::




Custom Search