Oracle Application Server 10g Migrating from WebSphere 10g (9.0.4) Part Number B10426-01 |
|
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:
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.
A JSP page typically consists of the following:
Each is described below.
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:
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" %>
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" %>
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.
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:
.java
file, which contains the Java language code for the servlet
.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, WebSphere generates files named _simple_xjsp.java
and _simple_xjsp.class
from the JSP file simple.jsp
.
.jsp
file name.
.jsp
file name extension in the URL, the servlet container of the Web server invokes the JSP container.
Translation includes producing servlet code in a .java
file and then compiling the .java
file to produce a servlet .class
file.
javax.servlet.jsp.HttpJspPage
interface.
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.
WebSphere provides several JSP features which are available in WebSphere only. These are:
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.
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:
<INSERT>
- This tag enables developers to insert a value based on a property name and an object specifier. This object can be a bean name or reference to a object in request object.
<REPEAT>
- This tag enables developers to write a "for" loop in a JSP page, as a HTML element, without embedding Java code. For example, a database query resulting in a variable result set can be iterated using a <REPEAT>
tag instead of a embedded Java "for" loop. A <REPEAT>
tag can contain a block of HTML tagging that in turn contains the <INSERT>
tags, and the HTML tags for formatting content. The <REPEAT>
tag iterates from the start value to the end value until either the end value is reached or an ArrayIndexOutofBoundsException
is thrown. The output of a <REPEAT>
block is buffered until the block completes. If an exception is thrown before a block completes, no output is written for that block.
<BEAN>
- This tag enables the developer to reference a bean in the JSP.
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 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:
<tsx:repeat>
- This tag is similar to the <REPEAT>
tag described above, useful in creating HTML tables.
<tsx:getProperty>
- This tag is an extension of the Sun JSP tag <jsp:getProperty>
. It is similar to <jsp:getProperty>
, and adds the ability to introspect a database bean that was created using the extension <tsx:dbquery>
or <tsx:dbmodify>
.
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.)
<tsx:dbconnect>
- This tag enables the JSP page to make a database connection to through JDBC. dbconnect tags are not used directly to establish a database connection. Instead, the <tsx:dbquery>
and <tsx:dbmodify>
tags are used to reference a <tsx:dbconnect>
in the same JSP file and establish the connection to the database. Note that this is different from what is done at the application server level, where you setup a set of datasources.
<tsx:userid>
and <tsx:passwd>
- These tags enable the JSP page to accept user input for the values and then add that data to the request object. The request object can be accessed by a JSP file, for example, Account.jsp
, that requests the database connection.These two tags should be used in within a <tsx:dbconnect>
tag.
<tsx:dbquery>
- This tag is used to establish a connection to a database using information specified in the <tsx:dbconnect>
tag in the same JSP file, and query the database and return the result set. This caches the result set in a results object. At the end of the operation it closes the connection.
<tsx:dbmodify>: <tsx:dbconnect>
- This tag is used to open a new connection to a database and then update the database tables. This tag is also similar to <tsx:dbquery>
in that it obtains database connnection information, and at the end of the operation closes the connection.
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:
JspScopeListener
for event handling
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.
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.
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 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.
This section explains how to migrate WebSphere JSP 0.91 files to OC4J.
<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.
<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" />
<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" />
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.)
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.
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>
.
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:
|
![]() Copyright © 2003 Oracle Corporation. All Rights Reserved. |
|