import java.io.*;
import java.net.*;

public class Query {
	public static void main (String[] args) {
		URL url;
		URLConnection urlconnection;
		PrintWriter out;
		BufferedReader in;
		StringBuffer buffer=new StringBuffer(100);
		String tempLine;
		
		try {
			// obtain HTTP connection to the URL specified
			url=new URL("http://sparc68.cse.cuhk.edu.hk:8080/examples/servlet/CompareXML");
			urlconnection=url.openConnection();
			urlconnection.setDoOutput(true);
			
			// obtain a handle to send data to CGI
			out=new PrintWriter(urlconnection.getOutputStream());
			
			// send the query
			out.print("field=ID&query=Nelson");
			out.close();
			
			// obtain a handle to read output from the CGI
			in=new BufferedReader(new InputStreamReader(urlconnection.getInputStream()));
			
			// loop until end
			do {
				tempLine=in.readLine();
				if (tempLine!=null) {
					buffer.append(tempLine);
				} else {
					break;
				}
			} while (true);
			in.close();
			
			// print out the string
			System.out.println(buffer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
