Skip Headers

Oracle9iAS Migrating From WebSphere
Release 9.0.2

Part Number A95110-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 Application Server Advanced Edition to Oracle9iAS 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 Oracle9iAS 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. Which JSP processor is 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

HTML Template Extensions in JSP 0.91

WebSphere Extensions to JSP 1.0

The OracleJSP container

Oracle's JavaServer Pages implementation is highly portable across server platforms and servlet environments. OracleJSP can run on any servlet environment that complies with version 2.0 or higher of the Sun Microsystems Java Servlet Specification.

The JSP Translator in Oracle9iAS OC4J

OC4J supports two JSP translators: the OC4J JSP translator, which is JSP 1.1 compliant, and the OJSP translator, which is JSP 1.1 compliant. The OC4J JSP translator is the default translator. Oracle tag libraries and data access beans work with both translators. You can use OJSP with OC4J if you need features such as NLS and SQLJ.


Note:

In Oracle9iAS Release 2, both the Oracle JSP and OC4J JSP translator implementations have been consolidated into one providing the best of both.


OracleJSP Extensions

OracleJSP provides some very useful functionality through custom tag libraries and custom JavaBeans, all of which are portable to other JSP environments. The extended functionality include:

OracleJSP also provides the following Oracle-specific extensions:

Support for SQLJ, a standard syntax for embedding SQL statements directly into Java code

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 © 2002 Oracle Corporation.

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