Conversion Steps
102 iPlanet Web Server, Enterprise Edition Programmer’s Guide to Servlets • May 2001
Conversion Steps
When converting applications, follow these steps:
1. Go over the structure of the application to see if there are helper classes that
provide functionality between pages. Convert these helper classes first so that
they are ready to use in your pages. (The
hangman example contains a helper
class, called
hangman.js in the original JavaScript application and called
JavaHangManUtil.java in the JSP application shipped with iPlanet Web
Server 6.0.) Write helpers as
.java files and compile them into .class files
before using them.
2. Define the methods within classes. The methods (functions in JavaScript) must
declare what they return and who can access them. For example, in JavaScript
you can write:
function InitAnswer(str) { function_code }
In Java, the same method must be declared as follows:
public static String InitAnswer(String str) { method_code }
This method passes in a String and returns a String. The public keyword
means that any other class can call this method. The static keyword means that
the virtual machine can run this method without creating an object of the class
containing the method.
3. Convert the client object of the application to a session bean. In Server-Side
JavaScript, data is easier to use in the client object. In a Java Session object, the
programmer must get data from the session and then put it back in if there are
changes. This work can be done in a wrapper bean. The bean handling
functionality of JSPs is very strong. You can specify the scope to be
session
and it is saved in the session automatically.
4. Convert the HTML files to JSP files. This mainly consists of finding the
<SERVER> and </SERVER> tags and replacing them with the <% and %> JSP tags.
Then go through and change the syntax to correct JSP or Java syntax.
5. It is sometimes necessary to add special lines to the file. For example, the line
<%@ page import="HangManUtil,HangBean" %>
imports helper classes, and the line
<jsp:useBean id="client" scope="session" class="HangBean"/>
uses a session bean.
Kommentare zu diesen Handbüchern