Talking to Web Applications
Web browsers are the universal clients for web applications. They
retrieve documents for display and serve as a user interface, primarily
through the use of HTML, JavaScript, and linked documents. In this
section, we‘ll show how to write client-side Java code that uses HTTP
through the URL class to work with
web applications directly using GET and POST operations to
retrieve and send data. Later in this chapter, we’ll begin a discussion of
web services, which marry HTTP with XML to enable cross-platform
application-to-application communications using web standards.
There are many reasons an application might want to communicate via HTTP. For example, compatibility with another browser-based application might be important, or you might need to gain access to a server through a firewall where direct socket connections (and RMI) are problematic. HTTP is the lingua franca of the Net, and despite its limitations (or more likely because of its simplicity), it has rapidly become one of the most widely supported protocols in the world. As for using Java on the client side, all the other reasons you would write a client-side GUI or non-GUI application (as opposed to a pure web/HTML-based application) also present themselves. A client-side GUI can perform sophisticated presentation and validation while, with the techniques presented here, still using web-enabled services over the network.
The primary task we discuss here is sending data to the server, specifically ...