Chapter 18. Network Clients II: Applets and Web Clients

Introduction

In Chapter 16, I discussed straightforward client applications that communicate over a socket. Chapter 17 covered simple server topics. Now we turn our attention to a variety of other client topics. First let’s look at Java-based web applet client programs. Applets are, as you probably know, small programs that run inside and under the control of a web browser. There’s a discussion of Applet versus JApplet and the Applet methods. Deploying an applet is no different from deploying a web page—you simply copy it into the web server directory—but you need an HTML page to invoke it (discussed in Recipe 18.1). We then discuss some additional client-side topics, such as loading a URL, that apply both to applets and to applications. Other books talk about servlets, which are programs similar to applets but designed to run inside the process of a web server. Applet deployment requires some considerations; see Recipe Recipe 23.6 for a means of ensuring that a user’s browser has a Java runtime compatible with your applet. Recipe 23.13 contains information on Java Web Start, which combines applet-like downloading with full application capabilities.

18.1. Embedding Java in a Web Page

Problem

You need to deploy a Java applet.

Solution

Use an <applet> tag in an HTML page.

Discussion

While this is not the place for a dissertation on the details of HTML, you should at least know that HTML is a tag-based textual language for writing ...

Get Java Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.