The rise of the Internet and the World Wide Web sparked a revolution not only in network communications but also in application design and development. Programmers have encapsulated pieces of business functionality into distinct objects or components, and then made them available as self-contained Web services that can be accessed using Internet-based protocols and tools.
As network servers have become capable of supporting Internet-based services, software developers have devised new programming paradigms to take advantage of the widespread availability of these services. This new class of software is categorized as Web-based or Web-enabled applications.
This section introduces some basic concepts and technologies that are helpful to understand when working with Web services and Web applications.
The term Web services can be confusing because it is used in many different ways. In most contexts, Web services are business logic components that can be connected together and exchange data to perform a useful task. The components can be internal or external to an organization, and they communicate using Internet-based protocols such as the HyperText Transfer Protocol (HTTP). In brief, Web services run on servers and process substantial amounts of data that users want to be able to access quickly and easily.
A popular programming model in which individual Web services are combined to create a functional whole is the service-oriented architecture. In this model, a service consumer sends requests to a service provider over a standard connection. The request and subsequent response are defined in a way that is understandable to both the consumer and provider.
Most Web services use Extensible Markup Language (XML) to define the format of request and response messages. XML features a tagged structure that provides the needed flexibility for exchanging data between disparate components. XML can also be used to define how data is stored in a database.
Simple Object Access Protocol (SOAP) provides a standard for enveloping and sending Web services messages. It is an XML messaging specification that describes a message format along with rules for exchanging data in the proper sequence between structured data types and arrays. SOAP generally uses HTTP, but it can use other standard Web protocols as well.
In the service-oriented architecture, service consumers can find available service providers through various discovery mechanisms. One such mechanism is the Universal Description, Discovery, and Integration (UDDI) registry. As Web services are developed, they can be added to the UDDI registry. The registry can then be searched in various ways to find the Web services available for a particular organization and obtain contact information.
In its simplest form, a Web application is an interactive system that allows its users to execute business logic that resides on a server and to view the results of that logic through a Web browser on a client workstation. The defining factor that makes the system a Web application is that the server and client communicate over the Internet. In brief, Web applications make the data processed by Web services available to users quickly and easily through their Web browsers.
Web applications are built on a client/server architecture. The business logic is contained in the application itself, which runs on a Web server and uses HTTP to communicate with clients over the Internet. The Web server manages the application, passes requests from clients to the application, and returns the application's responses to the client.
On the client side, the Web application is viewed with a browser. The application's user interface takes the form of HyperText Markup Language (HTML) pages that are interpreted and displayed by the browser. In addition to text, these HTML pages can contain Web forms, image files, audio and video clips, and other types of displayable data.
Although Web applications can use a Web site as the front end to their business logic, you can do many things in a Web application that you can't do with a static Web site, such as:
Identify specific users and present a customized interface for each user
Collect information from users and store that information on the server
Perform tasks for users, such as retrieving information from a database, registering to access specific content, or placing an order for a product
Java has become a standard programming language for Web applications because it is simple and portable to various hardware platforms. All you need to run Java applications is a Java Virtual Machine (JVM) for your particular platform. JVMs are available for almost every server platform in existence, including SUSE Linux Enterprise Server 10, Novell NetWare, Sun Solaris, Microsoft Windows, and Apple Macintosh OS.
Java 2 Platform, Enterprise Edition (J2EE) is a widely used environment for developing enterprise Web applications. J2EE offers a multitiered distributed application model, the ability to reuse components, integrated XML-based data interchange, a unified security model, and flexible transaction control. Best of all, applications developed for a J2EE application server are not tied to any one vendor's products or APIs.
The J2EE specification defines the following components:
Servlets: A Java servlet is a server-side component that provides a simple, consistent mechanism for extending the functionality of a Web server and for accessing existing business systems. A servlet dynamically processes client requests and constructs responses. Servlets are commonly used to process forms, handle redirects or authenticate user names and passwords, and create dynamic content for a Web application.
JavaServer Pages: JavaServer Pages (JSPs) are text-based documents that execute as servlets but allow a more natural approach to creating Web content. JSPs allow Web developers to rapidly develop and easily maintain dynamic Web pages that leverage existing business systems. JSP technology separates the user interface from content generation, enabling the overall page layout to be changed without altering the underlying dynamic content.
Enterprise JavaBeans: Enterprise JavaBeans (EJBs) are the basic components of an architecture that allows developers to create objects that precisely model the structure and logic of a business application domain. The system-level details of building the distributed application are abstracted out, enabling domain experts to be developers who freely focus on solving business problems. EJB technology enables rapid development of distributed, transactional, secure, and portable Java-based applications.
Web applications employ various enabling technologies to make their content dynamic and to create user interfaces into the business logic on the server.
Foremost among the enabling technologies are scripting languages such as PHP and Perl.
PHP (PHP: Hypertext Preprocessor) is a powerful server-side scripting language that is easy to learn. It offers all of the power and flexibility of JSP, but does not require as much memory and processing power. You mix specially delimited PHP code in with regular HTML to create a dynamic Web page. PHP is commonly used to access Web databases such as MySQL. It also supports library extensions to leverage standard services such as LDAP, FTP, POP3, Java, and many others.
Perl (Practical Extraction and Report Language) is another server-side scripting language commonly used by Web programmers to create scripts for Web servers. It uses a syntax similar to C/C++ and its file-manipulation and text-manipulation facilities make it ideal for tasks involving software tools, database access, graphical programming, networking, and system management.
A complementary component for both servlets and JSPs is the servlet container. The container acts as a simple application server that executes Java servlets and renders Web pages that include JSP code. It provides necessary functions such as life cycle management and interaction with a Web server.
The official reference implementation of the Java servlet API is Jakarta-Tomcat, an open source project released under the Apache Software Foundation. Tomcat is typically used in conjunction with a Web server such as Apache.
MySQL is an open source, structured query language (SQL) Web database server that is often used by PHP and Perl developers because its syntax is similar to those languages. It offers fast performance and is designed to work well with Web servers. It is widely used in building basic database-driven Web applications.
PostgreSQL is another Web database server that offers more advanced features often found in commercial database systems, such as transactions, subselects, triggers, views, referential integrity, and sophisticated locking. It is often used to provide more complex database functionality for Web sites and Web applications.
In more sophisticated Web application models, an application server is added to enable the system to manage business logic and track the user's progress through the application. The application server software runs in a middle tier, between Web browser-based clients and back-end databases and business applications. The application server handles all of the application logic and connectivity that old-style client/server applications contained.
Examples of J2EE application servers are the open source JBoss application server and the commercial Novell exteNd Application Server.
The following diagram shows the basic architecture of the Web components and services that are commonly used to host Web sites and build Web applications.
Figure 1-1 Architecture of Key Web Components and Technologies