Reviews : Java Books : Web Development with JavaServer Pages :


Title: Web Development with JavaServer Pages
ISBN: 1884777996
US Price: $35.96
Publication Date: April 2001
Pages: 584
© 2001 Manning Publications Co.

Web Development with JavaServer Pages

ColdFusion

The primary differences among template systems, then, lie in their scripting languages, and the capabilities provided therein. ColdFusion, from Allaire, provides a set of HTML-like tags which were initially targeted at embedding database queries into web pages, but it has since been extended to support a wide variety of data sources for dynamic content generation. The adoption of HTML-like tags has the advantage that there is a single, consistent style of syntax throughout the page; the ColdFusion tags are comfortable to web designers because they look just like the other tags present in the document. ColdFusion supports both UNIX and Microsoft Windows platforms.

Active Server Pages

Microsoft's Active Server Pages, often abbreviated ASP, support multiple scripting languages, including PerlScript, Jscript, and VBScript. PerlScript is based on Perl, and Jscript is based on JavaScript but the default scripting language for ASP is VBScript, a subset of Microsoft's popular Visual Basic programming language. VBScript includes support for accessing ActiveX components, which are compiled code objects that can encapsulate virtually any functionality, including database access and file manipulation. A large body of commercial off-the-shelf ActiveX components is available, and Microsoft provides tools and documentation for writing your own, as well. The major limitation of ASP, however, is that it is available only with Microsoft's Internet Information Server (IIS), running under the Windows NT operating system.

NOTE As a result of its popularity, a number of vendors have developed tools for deploying ASP on other platforms. Chili! Soft, for example, has an ASP product for the Apache HTTP server running on the UNIX platform, which even supports interoperability between Active Server Pages and server-side Java (i. e., servlets and JSPs). Unfortunately, ASP derives much of its power from its sup-port for ActiveX components, which, at least at the time of this writing, are not widely available on non-Microsoft platforms.

Server-Side JavaScript

As you might expect, Server-Side JavaScript (SSJS) uses JavaScript as its scripting language. JavaScript is an object-oriented language (based on prototypes rather than classes) with a C-like syntax, but, although it has a similar name, it is not Java. SSJS is an extension of the core JavaScript language, which is also the basis for the popular client-side JavaScript language used for scripting web browsers. SSJS adds built-in features for database and email support, session management, and interoperability with server-side Java classes using Netscape's LiveWire technology. In a departure from the other dynamic content systems described here, SSJS is a compiled language. A collection of web pages containing SSJS is compiled into a web application that is executed whenever the corresponding URLs are requested. Like compiled Java code, compiled SSJS is not platform-specific with respect to hard-ware or operating system. SSJS is, however, specific to Netscape's HTTP servers (i. e., Netscape Enterprise Server and Netscape Application Server).

PHP

A fourth dynamic content system that is growing in popularity is PHP. PHP was originally an acronym for Personal Home Page tools. As its scope and functionality have grown over the years, that moniker is no longer adequate and the software is now referred to only as PHP. Like JavaScript, PHP employs a C-like syntax, and provides strong support for pattern matching and database access. Extensions for communicating with other network resources, such as mail and directory servers, are also available. Unlike most of the other dynamic content systems now available, however, PHP is an Open Source product. As with other Open Source products, such as the Linux operating system and the Apache HTTP server, PHP is not a commercial product. It is instead the result of contributions from a community of interested developers, freely contributing to and supporting its code base. One important result of its Open Source nature is that PHP is now available on a large number of platforms. PHP is compatible with Windows NT and several UNIX operating systems, and with a number of HTTP servers, such as Apache, Microsoft's IIS, and Netscape Enterprise Server.

Java servlets

In light of the importance of dynamic content generation to web development then, it was natural for Sun to propose extensions to Java in this domain. In much the same way that Sun introduced applets as small Java-based applications for adding interactive functionality to web browsers, in 1996 Sun introduced servlets as small Java-based applications for adding dynamic functionality to web servers. Java servlets have a programming model similar to CGI scripts, insofar as they are given an HTTP request from a web browser as input, and are expected to locate and/ or construct the appropriate content for the server's response.

Unlike traditional CGI programs that require spawning a new process to handle each new request, all of the servlets associated with a web server run inside a single process. This process runs a Java Virtual Machine (JVM), which is the platform-specific program for running (cross-platform) compiled Java programs. As illustrated in figure 1.2, instead of creating a process for each request, the JVM creates a Java thread to handle each servlet request. Java threads have much less overhead than full-blown processes, and execute within the processor memory already allocated by the JVM, making servlet execution considerably more efficient than CGI processing. Since the JVM persists beyond the life of a single request, servlets can also avoid many time-consuming operations, such as connecting to a database, by sharing them among all requests. At the same time, because servlets are written in Java, they enjoy all the benefits of the core Java platform: an object-oriented programming model, automatic memory management, cross-platform portability, and access to the rich collection of Java APIs now available for accessing databases, directory servers, network resources, and so forth.

When reduced to their essence, servlets provide a Java-based methodology for mapping HTTP requests into HTTP responses. Generating dynamic web content using servlets then, is accomplished by means of Java code that outputs the HTML (or other data) representing that content. In the case of HTML data, one approach is for the Java code to construct strings containing the appropriate markup text and then print those strings on the output stream associated with the HTTP response. This is often referred to as the out. println approach, because a significant portion of the resulting code consists of lines that start with this (or a very similar) sequence of characters.

Another option is to take a more object-oriented approach to modeling the response data, by first constructing a model of the page being constructed as a collection of Java objects. Many web pages, for example, can be modeled as a hierarchy of textual elements, including a title, various levels of headings, and paragraphs of text providing the content for each section, subsection, and so on. Java classes could be defined which represent each of these textual elements, as well as the page itself. The classes for the textual elements would provide methods for accessing and modifying their content. The page class would provide methods for adding and removing textual elements. When generating dynamic content, then, an instance of the page class is created, to which instances of the appropriate title, heading, and paragraph classes are then added. Once the complete model of the page was constructed, other methods could be called to render these objects as strings of HTML to be sent back as the servlet's response.

One popular library of Java classes that enables this style of dynamic content generation is the Element Construction Set (ECS), which, like PHP, Apache, and Linux, is an Open Source software effort. One of the key advantages of this object-oriented approach to dynamic content generation is that it lends itself to supporting multiple forms of document output. ECS, for example, supports output in both HTML and XML, and can be extended to support additional formats, as needed.

In a similar manner, the Swinglets toolkit from Javelin Software allows developers to construct servlet output using a set of components modeled after those of Java's Swing library of user interface components. The Swinglets library provides several classes for data presentation, including tables, links, buttons, and radio buttons. Data is added to these interface components, which may then be rendered in various formats, including HTML, Dynamic HTML, and WML (Wireless Markup Language, an HTML-like language geared toward wireless devices such as mobile phones).

A potential disadvantage of this approach, however, is that all document con-tents, both static and dynamic, reside in program source code. As a result, any change to such a document requires intervention by a programmer. An HTML page designer cannot change the layout of the page unless the associated source code is changed. Indeed, any change to the static elements of the document, such as changing the URL of a link or image, requires corresponding changes to the source code. This dilemma also applies to the out. println approach.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.