ChapterÂ 10.Â Applet-Servlet Communication
This chapter demonstrates several techniques by which applets can communicate with servlets. Weâre going to come at the topic from a slightly different angle than you might expect. Instead of assuming you have an applet and a servlet that need to communicate, weâre going assume you have an applet that needs to talk to some entity on the server and explore why sometimes that entity should be a servlet.
To get the ball rolling, letâs think about applets that need to communicate with the server. There are a number of good examples. Take a look at the administration applet that manages the Java Web Server. Think about how it worksâit executes on the client, but it configures the server. To do this, the applet and the server need to be in near constant communication. As another example, take a look at one of the popular chat applets. One client says something, and all the rest see it. How does that work? They certainly donât communicate applet to applet. Instead, each applet posts its messages to a central server, and the server takes care of updating the other clients. Finally, imagine an applet that tracks the price of a set of stocks and offers continuous updates. How does the applet know the current stock prices, and, more importantly, how does it know when they change? The answer is that it talks with its server.
Our interest in stock trading rose along with the Dow, so letâs continue with this hypothetical ...