You are on page 1of 11

Unit IV

MULTI-TIER APPLICATION DEVELOPMENT

4.1 Server-side Programming

Server-side Java (SSJ), sometimes called servlets. Servlet technology is robust and scalable
because of java language. Server-side scripting languages are a type of programming language
that runs on the server instead of the client. They can create dynamic websites and web
applications, perform scheduling and data mining tasks, automate processes such as
compilation, and send emails.
It is the program that runs on server dealing with the generation of content of web
page.
1) Querying the database
2) Operations over databases
3) Access/Write a file on server.
4) Interact with other servers.
5) Structure web applications.
6) Process user input.

Examples : The Programming languages for server-side programming are :


1) PHP
2) C++
3) Java and JSP
4) Python
5) Ruby

4.2 Introduction to Java Servlets

Today we all are aware of the need of creating dynamic web pages i.e the ones which have
the capability to change the site contents according to the time or are able to generate the
contents according to the request received by the client.

Servlets are the Java programs that run on the Java-enabled web server or application server.
They are used to handle the request obtained from the webserver, process the request,
produce the response, then send a response back to the webserver.
Properties of Servlets are as follows:
 Servlets work on the server-side.
 Servlets are capable of handling complex requests obtained from the webserver.
Servlet Architecture is can be depicted

Execution of Servlets basically involves six basic steps:


1. The clients send the request to the webserver.
2. The web server receives the request.
3. The web server passes the request to the corresponding servlet.
4. The servlet processes the request and generates the response in the form of output.
5. The servlet sends the response back to the webserver.
6. The web server sends the response back to the client and the client browser displays it on
the screen.

Advantages of a Java Servlet


 Servlet is faster than CGI as it doesn’t involve the creation of a new process for every new
request received.
 Servlets, as written in Java, and platform-independent.
 It is a server-side component, so Servlet inherits the security provided by the Web
server.
 The API designed for Java Servlet automatically acquires the advantages of the Java
platforms such as platform-independent and portability.
 Many Web servers that are suitable for personal use or low-traffic websites are offered for
free or at extremely cheap costs eg. Java servlet.

There are many advantages of Servlet over CGI. The web container creates threads for handling
the multiple requests to the Servlet. Threads have many benefits over the Processes such as
they share a common memory area, lightweight, cost of communication between the threads
are low. The advantages of Servlet are as follows:

1. Better performance: because it creates a thread for each request, not process.
2. Portability: because it uses Java language.
3. Robust: JVM manages Servlets, so we don't need to worry about the memory
leak, garbage collection, etc.
4. Secure: because it uses java language.

4.3 Applet to Applet communication

A Java applet can communicate with other Java applets by using JavaScript functions in the
parent web page. JavaScript functions enable communication between applets by receiving
messages from one applet and invoking methods of other applets.

AppletContext class provides the facility of communication between applets. We provide the
name of applet through the HTML file. It provides getApplet() method that returns the object of
Applet

myapplet.html

<html>
<body>
<applet code="ButtonApplet.class" width="150" height="150" name="btn">
</applet>

<applet code="ColorApplet.class" width="150" height="150" name="clr">


</applet>
</body>
</html>

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonApplet extends Applet implements ActionListener
{
Button btnColor;

public void init()


{
btnColor=new Button("Click");
btnColor.setBounds(50,50,60,50);
add(btnColor);
btnColor.addActionListener(this);
}

public void actionPerformed(ActionEvent e)


{
AppletContext ctx=getAppletContext();
Applet a=ctx.getApplet("clr");
a.setBackground(Color.red);
}
}

4.4 Applet to Servlet communication

The applet and servlet can use the same socket (or even several sockets) to communicate
interactively, sending messages back and forth.
HTML exhibits high performance by taking less time to load in the browser. However, when we
use HTML page for important user details, by default, all the parameters that are passed
appended in the URL. This compromises with the security. On the other hand, applet takes
more time to load but there is no problem with Java security. This is an advantage of this
technique.

Similar to HTML-to-servlet communication we need to perform applet-to servlet


communication. In HTML-to-servlet communication the browser window automatically forms
request URL and automatically forms query string having form data, when submit button is
clicked. In applet-to-servlet communication all these activities should be taken care of by the
programmers manually or explicitly as event handling operation.

4.5 JDBC in Java

Java database connectivity (JDBC) is the JavaSoft specification of a standard application


programming interface (API) that allows Java programs to access database management
systems. It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC drivers to connect
with the database. There are four types of JDBC drivers:

o JDBC-ODBC Bridge Driver,


o Native Driver,
o Network Protocol Driver, and
o Thin Driver

We can use JDBC API to access tabular data stored in any relational database. By the help of
JDBC API, we can save, update, delete and fetch data from the database. It is like Open
Database Connectivity (ODBC) provided by Microsoft.

1. JDBC-ODBC bridge driver


The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-
ODBC bridge driver converts JDBC method calls into the ODBC function calls. This is now
discouraged because of thin driver.

Advantage of JDBC-ODBC

o Easy to use.
o Can be easily connected to any database.
2. Native-API driver
The Native API driver uses the client-side libraries of the database. The driver converts
JDBC method calls into native calls of the database API. It is not written entirely in java.

Advantage:
o performance upgraded than JDBC-ODBC bridge driver.

3. Network Protocol driver

The Network Protocol driver uses middleware (application server) that converts JDBC
calls directly or indirectly into the vendor-specific database protocol. It is fully written in java.

Advantage:
o No client side library is required because of application server that can perform many
tasks like auditing, load balancing, logging etc.
4. Thin driver
The thin driver converts JDBC calls directly into the vendor-specific database protocol.
That is why it is known as thin driver. It is fully written in Java language

Advantage:
o Better performance than all other drivers.
o No software is required at client side or server side.

4.6 Using BLOB and CLOB objects


BLOBs are used to store binary information, such as images, while CLOBs are used to
store character information. BLOBs and CLOBs can store up to 4 Gigabytes of data
Blob and Clob together are known as LOB(Large Object Type). The following are the major
differences between Blob and Clob data types.

Blob Clob

The full form of Blob is a Binary Large The full form of Clob is Character Large
Object. Object.

This is used to store large binary data. This is used to store large textual data.

This stores values in the form of binary This stores values in the form of character
streams. streams.

Using this you can stores files like Using this you can store files like text files,
videos, images, gifs, and audio files. PDF documents, word documents etc.

MySQL supports this with the following MySQL supports this with the following
datatypes: datatypes:
 TINYBLOB  TINYTEXT
 BLOB  TEXT
 MEDIUMBLOB  MEDIUMTEXT
 LONGBLOB  LONGTEXT

In JDBC API it is represented by In JDBC it is represented by java.sql.Clob


java.sql.Blob Interface. Interface.

The Blob object in JDBC points to the The Blob object in JDBC points to the
location of BLOB instead of holding its location of BLOB instead of holding its
binary data. character data.

To store Blob JDBC To store Clob JDBC (PreparedStatement)


(PreparedStatement) provides methods provides methods like:
like:  setClob()
 setBlob()  setCharacterStream()
 setBinaryStream()

And to retrieve (ResultSet) Blob it And to retrieve (ResultSet) Clob it provides


provides methods like: methods like:
 getBlob()  getClob()
 getBinaryStream  getCharacterStream()
4.7 Storing Multimedia data into databases
Multimedia database is the collection of interrelated multimedia data that includes text,
graphics (sketches, drawings), images, animations, video, audio etc and have vast amounts of
multisource multimedia data.

Content of Multimedia Database management system :


1. Media data – The actual data representing an object.
2. Media format data – Information such as sampling rate, resolution, encoding scheme etc.
about the format of the media data .
3. Media keyword data – Keywords description relating to the generation of data. It is also
known as content descriptive data. Example: date, time and place of recording.
4. Media feature data – Content dependent data such as the distribution of colors, kinds of
texture and different shapes present in data.

Types of multimedia applications based on data management characteristic are :


1. Repository applications – A Large amount of multimedia data as well as meta-
data(Media format date, Media keyword data, Media feature data) that is stored for
retrieval purpose, e.g., Repository of satellite images, engineering drawings, radiology
scanned pictures.
2. Presentation applications – They involve delivery of multimedia data subject to
temporal constraint. Example: Annotating of video and audio data, real-time editing
analysis.
3. Collaborative work using multimedia information – It involves executing a complex
task by merging drawings, changing notifications. Example: Intelligent healthcare
network.

Areas where multimedia database is applied are :


 Documents and record management : Industries and businesses that keep detailed
records and variety of documents. Example: Insurance claim record.
 Knowledge dissemination : Multimedia database is a very effective tool for knowledge
dissemination in terms of providing several resources. Example: Electronic books.
 Education and training : Computer-aided learning materials can be designed using
multimedia sources which are nowadays very popular sources of learning. Example: Digital
libraries.
 Marketing, advertising, retailing, entertainment and travel. Example: a virtual tour of
cities.
 Real-time control and monitoring : Coupled with active database technology, multimedia
presentation of information can be very effective means for monitoring and controlling
complex tasks Example: Manufacturing operation control.
4.8 Multimedia streaming applications and JMF

The Java Media Framework API (JMF) enables audio, video and other time-based media to be
added to applications and applets built on Java technology. JavaFX is a set of graphics and
media packages that enables developers to design, create, test, debug, and deploy rich client
applications that operate consistently across diverse platforms.

What Is JMF?

JMF is a framework for handling streaming media in Java programs. JMF is an optional package
of Java 2 standard platform. JMF provides a unified architecture and messaging protocol for
managing the acquisition, processing and delivery of time-based media. JMF enables Java
programs to
(i) Present ( playback) multimedia contents,
(ii) capture audio through microphone and video through Camera,
(iii) do real-time streaming of media over the Internet,
(iv) process media ( such as changing media format, adding special effects),
(v) store media into a file.

 A method for working with time-based data in Java


 Acquisition, processing and delivery of media
 Handles real-time or stored audio and video
 Plugins can be dynamically loaded in system
 Add functionality to the system
 Codecs, Effects, Mux, Demux, Renderers
 Media handlers

Applications of JMF

 Teleconferencing
 Multimedia editing/sequencing
 Streaming multimedia web content

Software applications are becoming more and more distributed. Java has emerged as an ideal
programming language for developing Internet applications.

Some of the promising multimedia applications that are deployable over the Internet include
(i) video conferencing,
(ii) media-on-demand,
(iii) access to multimedia database over Internet,
(iv) interactive distance education,
(v) collaborative computing,
(vi) virtual reality based scene navigation,
vii) interactive games rich in 3D graphics, etc
One of JMF's important design considerations is to support standard protocols. JMF provides
these functionalities by working on top of RTP and RTCP.
The architecture of JMF is shown in Figure 1.3. One obvious feature of the architecture is that it
contains some native components that talk directly to hardware. These components include the
codecs, capturers and renderers. They are responsible for the capturing, coding/decoding and
playback of media data. These tasks are intimately related to the hardware, so a native
approach can help to boost performance and get around security issues, because Java code is
not allowed to have direct control over the hardware of the host operating system. Apart from
these exceptions, the core of JMF is implemented in pure Java.

Figure 1.3 JMF architecture

The hardware dependency of JMF creates an inconvenience for JMF applications, however. JMF
must be installed on any client machine that runs these applications. This is one reason why
JMF has not been very successful so far.
JMF components are designed after the model of media playback as shown in Figure. This
model is familiar to us because it is very similar to the way common electronic devices are
connected together - and how they have been for quite a long time. In this fundamental model,
a video camera represents a capture device; the media data (a video tape, for example) is
encapsulated as a data source; and the VCR, as a player, controls the playback of media data.
Finally, during playback, the data is rendered on destination devices such as loudspeakers and a
television.

You might also like