Java Reference
In-Depth Information
String code = this.extractNoCase(buffer,
"Code:<b></td><td>", "</td>", 0);
String site = this.extractNoCase(buffer,
"Official Site:<b></td><td><a href=\"", "\"", 0);
System.out.println("State name:" + name);
System.out.println("State capital:"+ capital);
System.out.println("Code:"+code);
System.out.println("Site:"+site);
}
/**
* Typical Java main method, create an object, and then
* start the object passing arguments. If insufficient
* arguments are provided, then display startup
* instructions.
*
* @param args Program arguments.
*/
public static void main(String args[])
{
try
{
if (args.length != 1)
{
System.out.println(
"Usage:\njava AjaxNonXML [state, i.e. Missouri]");
} else
{
AjaxNonXML d = new AjaxNonXML();
d.process(args[0]);
}
} catch (Exception e)
{
e.printStackTrace();
}
}
}
Most of the work for this recipe is done inside of the process method. The process
method begins by downloading the contents of the URL.
URL url = new URL("http://www.httprecipes.com/1/10/statehtml.
php?state="+state);
String buffer = downloadPage(url,10000);
Search WWH ::




Custom Search