Head First Java Chapter 18
Distributed Computing
When running client-server apps client wants to invoke with the servers’ objects ‘Helpers’ are used to handling all the low-level networking and I/O details.
Then ‘helpers’ make communication between them. The client calls a method on the client helper as if the client helper were the actual service. The client helper is a proxy for the Real Thing. Then client and server act as if they live in the same heap.
RMI (Remote Method Invocation) is used to take the client and service helper objects.
Since networking and I/O are used in RMI, it has a risk. So they throw exceptions all over the place. So the client has to acknowledge the threat.
There are protocols: JRMP or IIOP. JRMP is RMI’s ‘native’ protocol, made just for Java-to-Java remote calls. On the other hand, IIOP is the protocol for CORBA (Common Object Request Broker Architecture), and lets you create remote calls on things that aren’t necessarily Java objects. CORBA is usually much more painful than RMI because if you don’t have Java on both ends, there’s an awful lot of translation and conversion that has to happen.
Servlets
Steps for making and running a servlet
- Find out where your servlets need to be placed.
- Get the servlets.jar and add it to your classpath
- Write a servlet class by extending HttpServlet
- Write an HTML page that invokes your servlet
- Make your servlet and HTML page available to your server
Bullet points
- Servlets are Java classes that run entirely on (and/or within) an HTTP (web) server.
- Servlets are useful for running code on the server as a result of client interaction with a web page. For example, if a client submits information in a web page form, the servlet can process the information, add it to a database, and send back a customized, confirmation response page.
- To compile a servlet, you need the servlet packages which are in the servlets.jar file. The servlet classes are not part of the Java standard libraries, so you need to download the servlets. jar from java.sun.com or get them from a servlet-capable web server. (Note: the Servlet library is included with the Java 2 Enterprise Edition (J2EE))
- To run a servlet, you must have a web server capable of running servlets, such as the Tomcat server from apache.org.
- Your servlet must be placed in a location that’s specific to your particular web server, so you’ll need to find that out before you try to run your servlets. If you have a website hosted by an ISP that supports servlets, the ISP will tell you which directory to place your servlets in.
- A typical servlet extends HttpServlet and overrides one or more servlet methods, such as doGet() or doPost().
- The web server starts the servlet and calls the appropriate method (doGet(), etc.) based on the client’s request.