P1: c-161
SoftwareDesign WL040/Bidgoli-Vol III-Ch-24 June 23, 2003 16:25 Char Count= 0
290 SOFTWAREDESIGN ANDIMPLEMENTATION IN THEWEBENVIRONMENTprocessing that data (server-side processing) and then re-
turning information, usually in the form of a Web page, to
the client. CGI programming allows the server to access
files and other resources on the server. Although CGI is
general enough to allow any programming language to be
used, the most common language has been the interpre-
tive language Perl, a very flexible scripting language that
is strong in text-handling and accessing system functions.
Developers quickly found a number of limitations of
CGI. Each execution of traditional CGI modules requires
a new process to be created on the Web server, which
severely affects performance. It has no built-in session
management services, which makes it difficult to develop
e-business applications. Most CGI applications have tra-
ditionally used interpretive languages such as Perl, which
suffer from a number of software engineering disadvan-
tages; in particular, most do not have capabilities such
as type checking and exception handling and offer lim-
ited or no support for information hiding and inheritance.
Although not a serious limitation for small applications,
this makes it hard to write large Web applications that
satisfy quality requirements such as reliability, usability,
security, and scalability. The Apache server now includes
“mod-perl” and “mod.php,” which use threads to amelio-
rate the performance problem, but the other issues re-
main. One common strategy is to build an initial version
of the application in CGI, either a prototype or Version 1
application, then to rewrite the application in compiled
modules and scripted pages.The J2EE Platform
Although many applications are built using CGI, the cur-
rent trend is toward integrated technologies that avoid
some of the disadvantages of CGI. Many of the heavy
transactional-based Web sites, particularly those sup-
porting e-business, are building new Web sites with the
J2EE platform. The J2EE platform is not a product but
a standard that defines the behavior of various pieces
of technologies, and there are several implementations
of the standard (Patzer, 2000). The standard is defined
by one company (Sun), but products are available from
dozens of companies, including open-source solutions.
The J2EE platform, often in conjunction with Web ser-
vice platforms, is currently used by many major Web-
based companies and services, including well-known sites
such as Netflix, eBay, Siemens, Amazon, the National
Science Foundation, Major League Baseball (mlb.com),
and MovieFone. This chapter discusses the individual
technologies.
The J2EE platform is centered around one language,
Java. Java program components are compiled to an inter-
mediate form called “bytecode,” which is executed by a
Java Virtual Machine (JVM). Java bytecode is intended
to be independent of hardware, operating system, and
browser, and thus can be moved between computers. Java
has simple built-in support for interfacing with other lan-
guages, thus providing support for connecting with legacy
systems.
The primary mechanism for server-side processing in
the J2EE standard is the Java servlet. Java servlets are
compiled-modules that collect data from the client’s Webbrowser into an object (the request object) with a sim-
ple API that can be accessed by servlets, and output
from servlets can be returned to the client (through the
response object). Servlets are Java classes that inherit
from the servlet base class, and execute as lightweight
threads within a plug-in called a servlet container. The
container cooperates with the Web server and takes care
of issues such as instantiating and destroying servlet ob-
jects, putting data from the client into the request ob-
ject and returning data from the response object to the
data.
The J2EE scripted page technology is Java Server
Pages. A simplistic view of JSPs is as an “inside-out” versi-
on of servlets. Instead of Java classes that produce HTML,
a JSP is an HTML page that includes Java statements. JSPs
are first translated into Java servlet classes then compiled
and run as servlets. This makes JSP execution clean and
efficient; the Web server does not need a completely new
plug-in module to support JSPs. In addition to the HTML,
JSPs contain declarations, which are translated to Java
class level variables and methods, Java scriptlets, which
are translated to blocks of Java statements and that can
make external method calls, and expressions, which are
values printed inside the HTML.
Integral parts of the J2EE environment are Java Beans
and Enterprise Java Beans. A Java bean is a design con-
vention rather than a language feature or plug-in technol-
ogy and is intended to be used to produce reusable soft-
ware components. A bean is a Java class that has three
characteristics: (a) it is a public class, (b) it has a public
constructor that has no arguments, and (c) it has pub-
lic get() and set() methods. Beans are based on the con-
cept of a property, which is a simple data object (such
as a variable) that defines some attribute of the software
application. Properties should be associated with only
two types of methods, getters, which return the property’s
value, and setters, which changes the property’s value. The
usual convention is that a property with name propName
is accessed through the methods getPropName() and
setPropName().
Despite the name, Enterprise Java Beans (EJBs) dif-
fer significantly from Java Beans. EJBs are intended to
implement all of the required business logic for Web ap-
plications. They are Java classes that follow a well-defined
set of rules and conventions that allow them to be installed
into and executed within the confines of an EJB container.
EJB containers are plug-ins that provide critical services
to their EJBs. Specifically, they handle life-cycle and re-
source management, transaction management, data per-
sistence, and security.
The final crucial element of the J2EE platform is
the ability to conveniently interact with databases. The
Java Database Connectivity (JDBC) API allows Java pro-
grams to store data into sequential databases using com-
mands that are independent of database vendor and
hardware–software platform. This allows a program to be
moved from, for example, a Unix platform using Oracle’s
database to a Windows computer using MS Access with
only a minimal number of changes. The runtime execu-
tion environment (JVM) translates the generic database
statements in the program to the vendor-specific database
access calls.