New York University

Computer Science Department

Courant Institute of Mathematical Sciences

 

Applets, Servlets, and Java Server Pages

 

Course Title: Application Servers                                           Course Number: g22.3033-011

Instructor: Jean-Claude Franchitti                                            Session: 3

 

There are three primary ways to create client interfaces to Java programs that are delivered over the Internet: applets, servlets, and Java Server Pages (JSP).  Applets run within a client browser, while servlets and JSPs run on the Web server machine.  Each method provides certain advantages and disadvantages in relation to the others.  Applets are better suited for high functionality Intranet and Extranet applications, where download times are not a factor.  Servlets and JSP pages are more appropriate for Internet and Extranet applications where the majority of the users may accessing the sight through a modem connection.

Applets

Applets are small programs that are downloaded into a Java Enabled Web Browser, like Netscape Navigator or Microsoft Internet Explorer.  The browser will execute the applet on the client’s machine.  The downloaded applet has very limited access to the client machine’s file system and network capabilities. These limitations ensure that the applet can’t perform any malicious activity on the client's machine, such as deleting files or installing viruses.  By default, a downloaded applet cannot read or write files from the file system, and may use the network only to communicate back to the server of origin.   Using security certificates, applets can be given permission to do anything on the user's machine that a normal Java application can do. This may be impractical for Extranet applications; however, as users may require support to give these permissions or may not trust an organization enough to grant such permission.

Enhanced User Interface

Applets greatly enhance the user interface available through a browser.  Applets can be created to act exactly like any other client-server GUI application including menus, popup dialog windows, and many other user-friendly features not otherwise available in a web browser environment.

Long Setup Time over Modems

On the downside, applets need to be downloaded over the Internet. Instead of just downloading the information to be displayed, a browser must download the whole application to execute it. The more functionality the applet provides, the longer it will take to download.  Currently, any applet or set of applets that represent an entire e-business application would take a prohibitive amount of time to download over a standard 28.8 kbs connection to the Internet.  Applets are best suited for applications that either run on an Intranet, or are small enough to download quickly and don't require special security access.

Servlets

A servlet is a Java program that runs in conjunction with a Web Server, like iPlanet (Netscape-Sun Alliance) Webserver.  Similar to a CGI script, a servlet is executed in response to an HTTP request from a client browser.  The servlet executes and then returns an HTML page back to the browser. 

Servlets Handle Multiple Request

Servlets are superior to CGI scripts because once a servlet is started it remains in memory and can handle multiple HTTP requests.  In contrast, a CGI program ends after each request and must be restarted for each subsequent request, reducing performance. 

Server Side Execution

Servlets do not run on the client, all execution takes place on the server.  While, they provide the advantages of generating dynamic content, they do not levy the same download time requirement as applets. 

Limited Functionality

Since they deliver HTML pages to their clients, the user interface available through a servlet is limited by what the HTML specification supports.

JSP (Java Server Pages)

Analogous to Microsoft Active Server Pages (ASP), JSPs are text documents that describe how a server should handle specific requests.  A JSP is run by a JSP Server, which interprets the JSP and performs the actions the page describes.  Frequently, the JSP server compiles the JSP into a servlet to enhance performance.  The server would then periodically check the JSP for changes.  If the JSP changes the server will recompile it into a servlet.

Extension of the Servlet API

The JSP specification is an extension of the servlet specification.  JSPs have the same advantages and disadvantages as servlets when compared to applets. 

Easier to Develop and Maintain than Servlets

To the developer, JSPs look very similar to static HTML pages, except that they contain special tags are used to identify and define areas that contain Java functionality.  Because of the close relationship between JSPs and the resulting HTML page, JSPs are easier to develop than a servlet that performs similar operations.  Because they do not need to be compiled, JSPs are easier to maintain and enhance than servlets. 

Initial Access Slower than Servlets

However, because they need to be interpreted or compiled by the server, response time for initial accesses may be slower than is experienced with servlets as the JSP is compiled.