How to call servlet from an applet, Readme File

Applet to Servlet Communication - Sample Application Readme

Date: 10/02/2004

Table of Contents

Introduction
Application Overview
Application Design
Sample Application Files
Setting up the Sample Application
Additional References

Introduction 

Prerequisite

To work your way through this Sample Application, a basic understanding of the fundamental concepts of Servlets, Java Swing and JDBC are required. For more information please refer Additional References.

Technical Overview

Java servlets provide a new and exciting method of developing server-side solutions. Servlets provide the features of traditional CGI scripts with the added benefits of efficiency and portability. They are programs that run on a Web server, generally used for generating dynamic web content. A servlet gets a request from a client such as a web browser, processes the request, and returns the response back to the client in the HTML format.

An applet is a java program that can be included in an HTML page. The applet runs on the JVM inside the browser providing rich UI capabilities on the browser. Applet communicates with the servlet for processing client side requests. To know more about Servlets/Applets refer the Additional References section at the end.

This Sample explains, how to build a 3-tier application that allows a Java applet to perform a two-way communication with a servlet. The focus will be on the concepts and techniques of applets communicating with servlets. The 3-Tier architecture is shown in the following figure.

Application Overview 

The sample application is a 3-tier application, where the applet on the client side interacts with the servlet which then interacts with the database. The applet displays Employees Organization chart using Swing's JTree components. At first, when the applet is loaded, applet interacts with the servlet to load employee details and construct employee organization tree. In turn, servlet interacts with the database to fetch employee details for the applet. Again, when the user selects particular employee from organization tree in the applet, it sends request to the servlet to return job details.

Application Design

Design Justification

The architecture used in this sample has the following advantages.
1. Eliminates JDBC library dependency on the client.
If the applet directly interacts with the database, it has to load database client libraries in every client. In the servlet-applet architecture, the database client libraries are required only by the servlet.
2. Database is not exposed to the client.
The database is not exposed to the client and can reside inside the firewall. The servlet is used indirectly to interact with the database.

Sample Application Files 

Readme file and Stylesheets

Directory File Description
ServletApplet/doc/ Readme.html This file gives introduction to the sample.
Install.html This file has instructions required to install and run the sample.

Java Source files for the Application

Directory File Description
ServletApplet/src/oracle/otnsamples/servlet/applet/ AppletToServlet.java This class is responsible to transfer request from applet to the servlet.
ConnectionDb.java This class provides actual implementation to create and close database connection.
ConnectionManager.java This interface will be used to get and close the database Connection and provides a layer of abstraction to establish the database connection.
ContentPanel.java This class is responsible for creating ContentPanel and to place all the swing components like JTree , JLable , JTextArea etc on the JPanel.
DbInteraction.java This class is responsible for interacting with the database and to provide all the necessary data from the database.
Employee.java This is a Serializable class used to transfer employee information from the servlet to the applet.
MainApplet.java This is an applet class, mainly responsible for getting the swing component and to display them in the HTML page.
MainServlet.java This is a HttpServlet, and the applet communicates with this servlet to retrieve the server side information.
ServletToApplet.java This class is responsible for transfering the data from the servlet to the applet.

ANT build Script

Directory File Description

ServletApplet/

build.xml This is an ANT build script.
build.properties

Contains the user parameters used by the ant to run the build.xml.

Configuration files for the Application

Directory File Description
ServletApplet/src/META-INF application.xml Contains application information.
data-sources.xml Contains the data source information.
data-sources._xml Contains the data source information. This file will be used while deploying the sample by using ant.
orion-application.xml Contains the OC4J specific information.

 

HTML files for the Application

Directory File Description
ServletApplet/web/ welcome.html This is the welcome page which will show the employee organization chart.

 

JDeveloper project files.

Directory File Description
ServletApplet/ ServletApplet.jpr JDeveloper Project File
ServletApplet.jws JDeveloper WorkSpace File
ServletApplet.deploy Deployment File

 

Setting up the Sample Application 

Refer to Install.html for step-by-step instructions on copying files, installing packages, and other configurations to successfully run the sample.

Additional References


We hope you find this README file helpful. Please enter your comments about this sample in the OTN Sample Code Discussion Forum.

Applet to Servlet Communication - Sample Application

Please rate this sample application :
Excellent
Good
Average
Below Average
Poor
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy