Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Networking our whiteboard with servlets

Find out how to easily replace the RMI and sockets networking layers with servlets

You gotta be Java.

Play with the whiteboard!

Note: This applet will run only in the HotJava browser, the Windows 95/NT implementation of Internet Explorer 4.0, or in an AWT 1.1-enabled version of Netscape (see Resources for a link to the patch required to bring Netscape up to speed).

If you are not using any of these browsers, you can use appletviewer to view the applet.

The whiteboard we're using was first developed back inNovember's column. The whiteboard uses 1.1 AWT features, such as lightweight components to display objects as the user draws them.

The whiteboard



In December's column we added to the functionality of the previous month by creating a network of whiteboards that shared a common list of objects. All the whiteboards in the collaborative group could add and move the shared whiteboard objects. We developed both RMI- and sockets-based networking layers to enable communication among the whiteboards.

This month we're going one step further: We're going to use servlets to provide the same function that sockets and RMI provided last month.

Servlets are server extensions written in Java, usually for Web servers. A growing number of Web servers support them, including Apache, Java Web Server (JWS), O'Reilly's WebSite, and Netscape's various offerings.

Servlets are interesting because they don't fork a new process for every request that comes in, which makes them much faster than CGI. Under some Web servers, such as JWS, servlets are even faster than Fast-CGI because there is no process task switch; the servlets run as threads within the server process itself.

Because Web-based servlets respond to HTTP methods such as GET and POST, servlet-based communication is able to get around firewalls, which block sockets and RMI. As an added bonus, it's easy to use SSL to secure communications between SSL-enabled clients (Netscape, for example) and servlets running under an SSL-enabled Web server. SSL (or Secure Sockets Layer) is an encryption-based protocol used to protect data sent over the Internet from eavesdropping.

Servlet structure and life cycle

At a high level, servlets are just like applets, with the exception that they run in the server environment instead of the browser environment. Like applets, they have a definite life cycle, which is controlled by the environment. Unlike applets, however, only one instance of a servlet is actually created for each Web server. Each request to the servlet's URL is passed into the same instance of the servlet.

Servlets are accessed from clients in the same manner as CGI scripts. For example, an HTTP GET request to a URL like http://www.mycom.com/servlet/CurrentTime could return a bit of HTML containing the current time on the server.

The server loads the servlet when the first request is directed to it (unless the server allows pre-loading). The server then calls the servlet's init () method. All other requests arriving before the init () method completes block until it does so.

Once the init () method completes, the servlet is ready to service requests via its service () method. The environment puts each request into its own thread, which then enters the servlet's service () method.

1 | 2 |  Next >
Resources
  • Download the article and the complete source as a gzipped tar file
    http://www.javaworld.com/javaworld/jw-01-1998/step/jw-01-step.tar.gz
  • Download the article and the complete source as a zip file
    http://www.javaworld.com/javaworld/jw-01-1998/step/jw-01-step.zip
  • The JavaSoft Servlets page contains information about servlets and includes a link to the Servlet Development Kit (JSDK) http://jserv.javasoft.com/products/java-server/servlets/
  • Apache's Java development effort has its own site, with information about
  • current Java modules, links of interest, and downloads http://java.apache.org/
  • Download the Apache Week patch for mod_servlet.c http://www.apacheweek.com/issues/97-06-13#status
  • Apache's Java group provides an Apache/servlet mailing list http://java.apache.org/
  • JavaSoft's Java Web Server site is the reference site for JWS, offering
  • downloads -- plus information on how to subscribe to the JWS mailing list http://jserv.javasoft.com/index.html
  • The W3C maintains the HTTP protocol reference site http://www.w3.org/Protocols/
  • W3C provides an in-depth CGI spec reference http://www.w3.org/CGI/
  • Step-by-step instructions on how to apply the Netscape 4.03 patch for Windows and some flavors of Unix http://developer.netscape.com/software/jdk/download.html#NT_INSTALL
  • Previous Step by Step articles