Skip Headers

Oracle Application Server 10g Migrating from WebSphere
10g (9.0.4)

Part Number B10426-01
Go To Documentation Library
Home
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

4
Migrating JSPs

This chapter describes how to migrate JavaServer Pages (JSPs) from WebSphere to Oracle Application Server OC4J. The JSP API, and the details of the WebSphere extensions and different JSP engines it supports are discussed. The process of migrating JSPs from WebSphere to Oracle Application Server is outlined at the end of the chapter. The chapter is organized as follows:

Overview of JSP 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.

Parts of a JSP Page

A JSP page typically consists of the following:

Each is described below.

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:

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" %>

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" %> 

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.

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:

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, WebSphere generates files named _simple_xjsp.java and
_simple_xjsp.class from the JSP file simple.jsp.

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.

WebSphere Support for the JSP API

WebSphere Advanced Edition 3.5.3 supports JSP 0.91, JSP 1.0, and, in its latest service pack, JSP 1.1. However, the support is not backward compatible.

WebSphere specifies two modes of operation for JSPs: Compatibility mode and Compliance mode. In Compatibility mode, you can choose compatibility with JSP 1.0 or JSP 0.91. For example, if you choose compatibility mode with JSP 0.91 you cannot use features of JSP 1.0 or JSP 1.1. In compliance mode, your applications are compliant with JSP 1.1.

These modes of JSP are necessary because WebSphere provides a JSP processor for each supported level of the JSP specification. Each of these JSP processors is a servlet that can be added to a web application to handle all JSP requests specific to the web application. The JSP processor used is dependent on the web application. If a web application includes JSPs of version 1.0, WebSphere loads the JSP processors for JSP 1.0. These is specified as a part of your web application.

Table 4-1 JSP Processors
JSP Processor Processor Servlet Name Class Name

JSP 1.0

JSPServlet

com.sun.jsp.runtime.JspServlet in jsp10.jar

JSP 0.91

PageCompileServlet

com.ibm.servlet.jsp.http.pagecompile.
    PageCompileServletinibmwebas.jar

WebSphere-Specific Features

WebSphere provides several JSP features which are available in WebSphere only. These are:

Batch JSP Compiler

WebSphere provides a batch JSP compiler, enabling faster responses to requests for the JSP files. The process of batch compilation is different for JSP 0.91 and JSP 1.0.

HTML Template Extensions in JSP 0.91

WebSphere has built-in extensions for JSPs called HTML templates for variable data. These extensions are supported by the WebSphere JSP engine and are useful for generating tabular data.These template extensions consist of three additional tags:

JSP also has tags for database connect, query, and modify: <DBCONNECT>, <DBQUERY> and <DBMODIFY>. The functionality of these tags has not changed in JSP 1.0 other than being moved to a new tag library, tsx, with names <tsx:dbconnect>, <tsx:dbquery>, and <tsx:dbmodify> respectively.

WebSphere Extensions to JSP 1.0

WebSphere Advanced Edition 3.5.3 provides several extensions to the base APIs. The extensions are categorized as tags for variable data and tags for database access.

Tags for variable data:

Tags for database access:

(These tags are useful for making database connections from a JSP and then use that connection to query or update the database. The user ID and password for the database connection can be provided by the user at request-time or hard coded within the JSP file.)

OC4J JSP Features

Oracle Application Server provides one of the fastest JSP engines on the market. Further, 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:

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.

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.

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:

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.

Migrating from WebSphere JSP 0.91

This section explains how to migrate WebSphere JSP 0.91 files to OC4J.

The <REPEATGROUP> Tag

  1. If you are migrating JSP 0.91 files that contain <REPEATGROUP> tags, you must change these tags. This tag is used for repeating a block of HTML, for data that is already logically grouped in the database.

  2. Replace the <SERVLET> tag with the <jsp:include> tag.

    For example, change the following:

    <SERVLET CODE="com.samples.test.TestServlet"></SERVLET>
    
    

    to

    <jsp:include page="/servlet/com.samples.test.TestServlet" />
    
    
  3. Replace the WebSphere <BEAN> tag with the <jsp:useBean> tag.

    The example below shows the <BEAN> tag migrated to the JSP standard tag:

    <BEAN NAME="AccountDBBean"
    TYPE="com.test.AccountDBBean"
    CREATE="YES"
    INTROSPECT="YES"
    SCOPE="request">
    <PARAM NAME="userID" VALUE="wsdemo">
    </BEAN> 
    
    

    Migrating to OC4J, the above is replaced by:

    <jsp:useBean
    id="AccountDBBean"
    type="com.test.AccountDBBean"
    class="com.test.AccountDBBea"
    scope="request"/>
    
    <jsp:setProperty
    name="AccountDBBean"
    property="userID"
    value="wasdemo" />
    
    
    • Note that the explicit attribute of CREATE="YES" is removed. This is because, if the bean with the name specified by the id attribute is not found within the specified scope, then an instance of bean will be created according to the class attribute. The JSP NAME attribute corresponds to the JSP 1.0 id attribute. It is no longer an INTROSPECT attribute. (The JSP 0.91 scope of requests and sessions carries over to JSP 1.0.)

    • The class attribute is not necessary if the bean already exists within the specified scope . But if the class attribute is not specified and the bean is not in the specified scope an error will occur when creating a new instance of the bean.

  4. Set the bean properties.

    In JSP 0.91, the <PARAM> tag is used within the <BEAN> tag to specify properties for the bean. In JSP 1.0, you must use the <jsp:setProperty> tag outside of the <jsp:useBean> tag. You can link to the property settings of an existing bean using the name attribute within <jsp:setProperty> and specifying the bean identified by the id attribute in <jsp:useBean>. A similar way to obtain bean property values can be achieved using the tag <jsp:getProperty>.

Migrating WebSphere Extensions to OC4J

There are two ways to migrate JSPs that use any WebSphere-specific custom tags defined in the tsx tag library to OC4J.

Following are code examples showing how to migrate WebSphere JSP extensions to OC4J using the Oracle JSP Markup Language (JML) tag library.

<REPEAT> or <tsx:repeat> tag:

These tags are provided by WebSphere for looping over a HTML block a specified number of times, as an altenative to writing a Java "for" loop within a JSP page. The Oracle JML tag library has a <jml:for> tag with the same functionality. The syntax for this tag is:

<jml:for id = " loopVariable"
    from = "<%= jspExpression %>"
    to = "<%= jspExpression %>" >
    ... body of for tag (executed once at each value of range, inclusive)...    
</jml:for>

which is similar to the WebSphere tsx:repeat:

<tsx:repeat index=name start=start_index end=end_index >
</tsx:repeat>

The differences are:


Go to previous page Go to next page
Oracle
Copyright © 2003 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Table Of Contents
Contents
Go To Index
Index