Sun Java Solaris Communities My SDN Account Join SDN
 
Article

JavaServer Pages[tm] Technology - Powering the Web Experience with Dynamic Content

 

Introduction

Download PDF Download PDF File
View & print PDF files with Adobe Acrobat Reader.

JavaTM Servlet technology has done much towards making Web application development an easier task. With a platform- and server-independent approach based on the JavaTM language, servlets provide developers with an easier way to build high-performance, dynamic Web pages compared to traditional CGI programs.

With JavaServer PagesTM (JSPTM) technology, Sun makes creating dynamic HTML and XML Web pages even simpler. JSP technology is a major extension of Java Servlet technology that makes building and maintaining dynamic pages much easier, and supports the distributed development model common in larger enterprises. JSP technology opens up dynamic pages to a wide range of page authors, while offering all of the benefits of the Java platform.

This paper describes how JSP technology extends the basic servlet framework to support easier and faster page authoring and maintenance. For those familiar with or already using servlets, incorporating the additional functionality of JSP technology is fast and easy. To find out more about how JSP pages fit with what you already do, please see the JavaServer Pages Technology for Servlet Developers paper.

Java Servlets: Building the Foundation for Dynamic Web Applications

As the server-side counterpart of an applet, Java servlets have made many Web applications possible. With Java servlets, Web developers get a simple, consistent mechanism for extending the functionality of a Web server and accessing existing business systems.

Today, servlets are a popular choice for building interactive Web applications. Third-party servlet containers are available for the Apache Web server, iPlanetTM Web Server (formerly NetscapeTM Enterprise Server), Microsoft IIS, and others. Servlet containers can also be integrated with Web-enabled application servers such as the BEA WebLogic application server, IBM WebSphere, Netscape Application Server, and more.

A major advantage is of servlets is that they provide a component-based, platform-independent method for building Web-based applications - without the performance limitations of CGI programs. And unlike proprietary server extension mechanisms (such as the Netscape Server API or Apache modules), servlets are both server and platform independent. This enables companies to select a best-of-breed strategy for their servers, platforms, and tools.

Written in the Java language, servlets have access to the entire family of Java APIs, including the JDBCTM API, to access enterprise databases. Servlets can also access a library of HTTP-specific calls, and offer all the benefits of the mature Java language, including portability, performance, reusability, and crash protection. But for all of their benefits, servlets are still primarily a developer's tool. With JSP technology, the capabilities of servlets have been extended to a broader audience of page authors.

JavaServer Pages: Authoring Pages Instead of Writing Programs

A JSP page is actually compiled into a servlet when it is called, so JSP technology is truly an extension of servlet technology. However, JSP pages make servlets much easier to write and maintain by changing the approach to creating servlets.

A page created with JSP technology can be thought of as an "inside-out" servlet. In a servlet, fixed page elements (such as text) are embedded in the application logic (for example, in an out.println statement). Between the statements and the other programming overhead (such as preambles and boilerplates), it can be difficult to even find the fixed elements, much less change them.

In contrast, a JSP page embeds the application logic within standard HTML (or XML) templates. Page authors can create or edit page design elements or text without affecting application logic at all. Because the JSP format automatically takes care of the programming overhead, and the JSP container automatically compiles the page when it is called, the process of creating and revising pages is greatly simplified versus that of writing and compiling servlet programs.

The application logic, which is embedded in the JSP page, may be in one of the following forms:

  • Java scriptlets: Script fragments that perform simple processing

  • JSP tags that call external functions, for example, a USEBEAN tag gives the page author easy access to a JavaBeansTM component that may perform some basic functionality

  • Customized JSP tags; Developers can create customized tag libraries that page authors may call with a simple, XML-like syntax

Easier and Faster Page Authoring

JSP technology simplifies and speeds the development process for developers and page authors alike by separating code development and page layout activities.

  • Instead of writing a program, page authors simply write a page using traditional HTML, then add the XML-like tags and, if necessary, scriptlets to tie everything together. Most of the programming overhead is automatically taken care of by the JSP container.

  • The pages automatically compile into servlets when called, so the page author does not need to worry about compiling changes. JSP pages can also be precompiled into servlets.

  • Developers can write beans, servlets, or customized tag libraries, and then distribute them to a wide range of page authors. This makes everyone more efficient - developers can concentrate on developing and everyone else can make use of their efforts, quickly and easily.

  • By supporting component-based development and customized tag libraries, JSP technology not only simplifies page authoring but also provides a strong foundation for a wide range of page authoring tools, which are now becoming more and more available.

Simplified Application Maintenance Through Separation of Content and Logic

JSP pages are not only fast to deploy, they are easy to maintain over time. This is due to the separation of application logic (typically residing within customized tag libraries or beans) from page design/content.

For example:

  • A page author can change fixed text on the page without affecting the application logic at all. The JSP container will recompile the page automatically the first time it is called.

  • Likewise, application developers can create, distribute, and edit application logic through customized JSP tag libraries. They can revise components without changing the individual pages that access the components.

Using JSP technology, individuals responsible for pages can make content changes without requiring a developer's time. This leads to faster application changes and overall easier application maintenance.

JSP Pages Fit Within Many Architectures

There are many ways to use JSP pages within a broader Web-based application. As part of the Java family, JSP technology has access to all of the Java APIs and components. For example, a JSP page may include a request of a servlet to process information. The JSP page could determine details of the request, and then forward the request appropriately based on the request properties.

A JSP page may access other data sources directly, using the appropriate Java invocation method. JSP pages and servlets can access relational databases through the JDBC API. In the future, custom tags will handle the database management functions.

The architecture diagrammed below is a simple method for accessing data sources, and suits relatively low-volume applications.

JSP pages may call other Java components, such as Enterprise JavaBeansTM (EJB) components. For example, an EJB component and container can manage access to external resources, providing better performance for high-volume applications. By implementing custom JSP tags to support calls to these resources, the page author can be shielded from the details of the enterprise environment.

A Java Solution for the Enterprise

JSP and Java Servlet technologies offer all the advantages of the Java language, a mature, simplified solution suitable for both large and small applications. It offers:

  • Portability across platforms and servers

  • Robust exception management and memory management

  • Access to the wide range of Java APIs (JDBC, JavaMailTM, etc.)

JSP and Java Servlet technologies are part of the Java 2 Platform, Enterprise Edition (J2EE), and provide a highly flexible and scalable solution for building multitier applications in the enterprise environment because they:

  • Can access Enterprise JavaBeans and J2EE components and containers that package a wide range of application functionality, including security and transaction management

  • Provide multithreaded processing and multiple concurrent requests, supporting applications with large numbers of concurrent users

In conclusion, using JSP and Java Servlet technologies helps leverage all the benefits of Java technology for rapid application deployment and easier application maintenance. Servlets and JSP pages can support large-scale interactive Web applications in the enterprise environment with a distributed development model. Web developers can create cross-platform application components as JavaBeans, Enterprise JavaBeans, or customized tag libraries. And page authors can use a simplified interface to integrate this logic into their page designs.