Link to home
Start Free TrialLog in
Avatar of beneflex
beneflex

asked on

Java RMI

Does anyone know the disadvantages of Java RMI? Thanks in advance!!!
ASKER CERTIFIED SOLUTION
Avatar of Jod
Jod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of beneflex
beneflex

ASKER

Thanks Jod!
Jod,
I read Jason Hunter's excellent book on Servlets where he talks abt Servlets and RMI ,what is the use of having them both?

I mean servlet acts as a Client or sometimes as a Server?Pls expalin?

Thanks
Amit
To quote:

What an applet is to a browser, a servlet is to a server. In simple terms, servlets are Java programs that are executed inside a server, usually, but not necessarily, a web server. Servlets can do anything a cgi script can do and usually faster, since cgi-script start-up overhead is avoided, and the Java intrerpreter is embedded in the web-server.

Servlets are an extension to your Web Server to create dynamic html that can display web pages that change based on data in a database or the current user or the time or whatever.

When you request a page from a web server then if that page is partly or totally created by a servlet then the web server will load the servlet and using http requests will return a page or data within a page to the client browser.

For example, a servlet could be used to create a shopping basket application that tracked the current user and showed the details of items they may want to purchase on your site by displaying these in the web page.

Previously, this would be done with CGI programs which are generally not portable, can be slow and often don't provide many advanced features for web pages.

However, Servlets are not limited to this and have full access to all the Java API so Jason Hunters book provides examples of how to extend servlets to use RMI to communicate with applets in order to provide more features and a greater level of communication with the client browser.

The link below has lots of info to help clarify things.

http://www.cs.odu.edu/~cs745/presentations/servlet/

A simple servlet looks like this:


import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;


/**
 * This is a simple example of an HTTP Servlet.  It responds to the GET
 * and HEAD methods of the HTTP protocol.
 */
public class SimpleServlet extends HttpServlet {

    public void doGet (HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException
    {
        ServletOutputStream out = res.getOutputStream();

      // set content type and other response header fields first
        res.setContentType("text/html");

      // then write the data of the response
        out.println("<HEAD><TITLE> SimpleServlet Output </TITLE></HEAD><BODY>");
      out.println("<h1> SimpleServlet Output </h1>");
      out.println("<P>This is output from SimpleServlet.");
      out.println("</BODY>");
      out.close();
    }

    public String getServletInfo() {
        return "A simple servlet";
    }
}

It responds to certain methods of the HTTP protocol that could be invoked by the browser when you open a page. In this case, it dynamically creates a page and displays it by passing the html text out through the HttpServletResponse outputstream which is passed into the doGet method.

Servlets can also be extended to do things when buttons are pressed on html forms or to be embedded in parts of an existing html page.

However there are a limited number of ways to communicate with a servlet over HTTP, so using RMI will allow you to invoke various methods in the servlet
that could provide more advanced functions.

Also it is easier to write and use Servlets than develop standalone Applications which run on the server, so you can use RMI to communicate with the servlet which can then have (nearly) all the functionality of a server based application which communicates with your Applet.

The only limitation is that servlets have no user interface of their own, but this is not really a problem with server side services.
Thanx ,will read it and let u know.
:-)