Skip to Main Content
Java Servlet Programming
book

Java Servlet Programming

by Jason Hunter
November 1998
Intermediate to advanced content levelIntermediate to advanced
526 pages
14h 38m
English
O'Reilly Media, Inc.
Content preview from Java Servlet Programming

Daytime Server

For a simple demonstration of each communication technique, we’re going to write an applet that asks its server for the current time of day. The applet first uses an HTTP connection, then a non-HTTP socket connection, and finally an RMI connection. Of course, an applet can normally get the current time from the system on which it’s running. To give this example an air of practicality, let’s assume the applet needs an approximate time stamp for some event and cannot rely on the client machine to have a correctly set clock.

The Applet

We’re going to be using the same example applet throughout this section. The skeleton code for this applet, DaytimeApplet, is shown in Example 10.1. Right now, the applet just creates a user interface where the times it retrieves can be displayed, as shown in Figure 10.1. As we proceed with this example, we’ll implement its getDateUsingHttpText(), getDateUsingHttpObject(), getDateUsingSocketText(), getDateUsingSocketObject(), and getDateUsingRMIObject() methods. Note that the examples in this chapter use several JDK 1.0 methods that are deprecated in JDK 1.1. This is to maximize portability.

The DaytimeApplet user interface

Figure 10-1. The DaytimeApplet user interface

Example 10-1. DaytimeApplet, without all the good stuff

import java.applet.*; import java.awt.*; import java.io.*; import java.util.*; public class DaytimeApplet extends Applet { TextField httpText, httpObject, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Servlet Programming, 2nd Edition

Java Servlet Programming, 2nd Edition

Jason Hunter, William Crawford

Publisher Resources

ISBN: 156592391XSupplemental ContentCatalog PageErrata