Java Reference
In-Depth Information
L ISTING 6.3
Continued
6
}
else {
System.err.println(“readObject failed.”);
}
System.out.println(“\n Press enter to quit.”);
System.in.read();
}
catch (MalformedURLException mue) {
System.err.println(mue.getMessage());
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}
public static void main(String[] args) {
StudentListTunnelApp studentListTunnelApp =
new StudentListTunnelApp();
studentListTunnelApp.invoke();
}
}
Take a look at exactly how the client works. You need to focus on several areas of this exam-
ple. The first is creating the URL and opening the URLConnection . This section is listed as fol-
lows:
// create our URL
URL url = new URL(“http://localhost/djs” +
“/servlet/StudentListTunnelServlet”);
// Open our URLConnection
System.err.println(“Opening Connection.”);
URLConnection con = url.openConnection();
This is a very simple procedure. It first instantiates a URL object with a string pointing to the
servlet URL. It then calls the URL.openConnection() method, which returns a URLConnection
object. This is the object you will be using as your communications medium. It will be passed
to the writeStudentList() and readStudentList() methods. These methods are your next
areas of focus.
 
Search WWH ::




Custom Search