Skip Headers
Oracle® Application Server Migrating from JBoss
10g Release 3 (10.1.3.1.0)

Part Number B25219-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

4 Migrating Java Server Pages

This chapter describes support for JavaServer Pages (JSPs) from JBoss and Oracle Application Server OC4J. The JSP API is discussed.

4.1 Overview of Java Server Pages

JavaServer Pages is a technology specified by Sun Microsystems as a method of generating dynamic content from an application running on a web server. This technology, which is closely coupled with Java servlet technology, allows you to include Java code snippets and calls to external Java components within the HTML code (or other markup code, such as XML) of your Web pages.

A JSP page is translated into a Java servlet before being executed (typically on demand, but sometimes in advance). As a servlet, it processes HTTP requests and generates responses. JSP technology offers a more convenient way to code the servlet instead of embedding HTML tags in the servlets. Furthermore, JSP pages are fully interoperable with servlets—that is, JSP pages can include output from a servlet or forward output to a servlet, and servlets can include output from a JSP page or forward to a JSP page.

4.1.1 Parts of a JSP Page

A JSP page typically consists of the following:

  • Directives - imports and and interfaces

  • Declarations - class-wide variables and methods

  • Expressions - return value substitution

  • Scriptlets - inline Java code

Each is described below.

4.1.1.1 Directives

Directives are compile-time control tags. They allow you to customize how your JSP pages are compiled to Java servlets. There are three types of directives:

4.1.1.1.1 Page

A page directive is placed at the top of a JSP page. Its attributes apply to the entire page.

Example:

<%@ page language="java" import="com.mycom.*" buffer="16k" %>

4.1.1.1.2 Taglib

A taglib directive extends the set of tags recognized by the JSP processor. It requires two attributes, uri and prefix.

Example:

<%@ taglib uri="tag-lib-uri" prefix="tag-prefix" %>

The uri attribute contains the location of the tag library TLD (Tag Library Descriptor) file.

The prefix attribute specifies the tag prefix you want to use for your custom tag.

Example:

<%@ taglib uri="/WEB-INF/tlds/myapp.tld" prefix="custom" %> 

4.1.1.1.3 Include

The include directive enables you to insert the content of another file into the JSP page at compilation time. Its syntax is as follows:

<%@ include file="localOrAbsoluteURL" %>

During compilation the content of the file specified in the file attribute will be added to the current JSP page.

4.1.2 What is a JSP container?

A JSP container is software that stores the JSP files and servlets, converts JSP files into servlets, compiles the servlets, and runs them (creating HTML). The exact make-up of a JSP container varies from implementation to implementation, but it will consist of a servlet or collection of servlets. The JSP container is executed by a servlet container.

The JSP container creates and compiles a servlet from each JSP file. The container produces two files for each JSP file:

  • A .java file, which contains the Java language code for the servlet

  • A .class file, which is the compiled servlet

The JSP container puts the .java and the .class file in a path specific to the container. The .java and the .class file have the same filename. Each container uses a naming convention for the generated .java and .class files. For example, JBoss generates files named _simple_xjsp.java and _simple_xjsp.class from the JSP file simple.jsp.

4.1.3 Life Cycle of a JSP Page

  1. The user requests the JSP page through a URL ending with a .jsp file name.

  2. Upon noting the .jsp file name extension in the URL, the servlet container of the Web server invokes the JSP container.

  3. The JSP container locates the JSP page and translates it if this is the first time it has been requested.

    Translation includes producing servlet code in a .java file and then compiling the .java file to produce a servlet .class file.

  4. The servlet class generated by the JSP translator subclasses a class (provided by the JSP container) that implements the javax.servlet.jsp.HttpJspPage interface.

  5. The servlet class is referred to as the page implementation class. This document will refer to instances of page implementation classes as JSP page instances.

4.2 JBoss Support for the JSP API

JBoss 3.2.6 supports JSP 1.0.

4.2.1 OC4J JSP Features

Oracle Application Server provides one of the fastest JSP engines on the market. It also provides several value-added features and enhancements such as support for globalization and SQLJ. If you are familiar with Oracle9iAS 1.0.2.2, the first release of Oracle Application Server to include OC4J, there were two JSP containers: a container developed by Oracle and formerly known as OracleJSP and a container licensed from Ironflare AB and formerly known as the "Orion JSP container".

In Oracle Application Server 10g, these have been integrated into a single JSP container, referred to as the "OC4J JSP container". This new container offers the best features of both previous versions, runs efficiently as a servlet in the OC4J servlet container, and is well integrated with other OC4J containers. The integrated container primarily consists of the OracleJSP translator and the Orion container runtime running with a new simplified dispatcher and the OC4J 1.0.2.2 core runtime classes. The result is one of the fastest JSP engines on the market with additional functionality over the standard JSP specifications.

OC4J JSP provides extended functionality through custom tag libraries and custom JavaBeans and classes that are generally portable to other JSP environments:

  • Extended types implemented as JavaBeans that can have a specified scope

  • JspScopeListener for event handling

  • Integration with XML and XSL through custom tags

  • Data-access JavaBeans

  • The Oracle JSP Markup Language (JML) custom tag library, which reduces the level of Java proficiency required for JSP development

  • OC4J JSP includes connection pooling tags, XML tags, EJB tags, file access tags, email tags, caching tags, OracleAS Personalization tags, OracleAS Ultrasearch tags, and a custom tag library for SQL functionality.

  • JESI (Edge Side Includes for Java) tags and Web Object Cache tags and API that work with content delivery network edge servers to provide an intelligent caching solution for web content (see the following sub-sections).

    See Also:

    Oracle Containers for J2EE JSP Tag Libraries and Utilities Reference for detailed information on custom JSP tag libraries.

The OC4J JSP container also offers several important features such as the ability to switch modes for automatic page recompilation and class reloading, JSP instance pooling, and tag handler instance pooling.

4.2.1.1 Edge Side Includes for Java (JESI) Tags

OC4J provides fine-grained control allowing developers to cache fragments of JSP pages down to each individual tag - these can be cached in OracleAS Web Cache and are automatically invalidated and refreshed when a JSP changes. The technology behind this is Edge Side Includes (ESI), a W3C standard XML schema/markup language that allows dynamic content to be cached in a Web cache or to be assembled in an edge network. By caching this dynamic content, it reduces the need to execute JSPs or Servlets, thereby improving performance, off loading the application servers, and reducing latency. JESI (JSP to ESI) tags are layered on top of an Edge Side Includes (ESI) framework to provide ESI caching functionality in a JSP application. JESI tags enable the user to break down dynamic content of JSP pages into cacheable components or fragments.

4.2.1.2 Web Object Cache Tags

The Web Object Cache is an Oracle Application Server feature that allows Web applications written in Java to capture, store, reuse, post-process, and maintain the partial and intermediate results generated by JSPs or Servlets. For programming interfaces, it provides a tag library (for use in JSP pages) and a Java API (for use in Servlets). Cached objects might consist of HTML or XML fragments, XML DOM objects, or Java serializable objects. By caching these objects in memory, various operations can be carried out on the cached objects including:

  • Applying a different XSLT based on user profile or device characteristics on the stored XML

  • Re-using a cached object outside HTTP, such as SMTP to send e-mail to clients.

4.2.1.3 Oracle JDeveloper and OC4J JSP Container

Oracle JDeveloper is integrated with the OC4J JSP container to support the full JSP application development cycle - editing, source-level debugging, and running JSP pages. It also provides an extensive set of data-enabled and web-enabled JavaBeans, known as JDeveloper web beans and a JSP element wizard which offers a convenient way to add predefined web beans to a page. JDeveloper also provides a distinct feature that is very popular with developers. It allows you to set breakpoints within JSP page source and can follow calls from JSP pages into JavaBeans. This is much more convenient than manual debugging techniques, such as adding print statements within the JSP page to output state into the response stream for display on browser or to the server log.