|
Oracle9i Lite Developer's Guide for Web-to-Go
Release 5.0.1 Part No. A95259-01 |
|
This chapter provides instructions for developing Web-to-Go applications. Topics include:
Web-to-Go provides a high-level Java API that provides easy-to-use functionality to developers of mobile applications. By using this API, developers no longer need to write code for such functions as replication of database tables, online and offline database connections, security, directory locations, or deployment of applications to client devices.
In addition, the Mobile Development Kit for Web-to-Go allows developers to both develop and debug Web-to-go applications that contain Java applets, Java servlets, and JavaServer Pages (JSP).
Figure 3-1 Development Architecture
Web-to-Go applications adhere to Web standards and use browsers to display front-end and graphical user interface (GUI) elements. Generally, Web-to-Go applications access and manipulate data stored in databases. These applications contain static, dynamic, and database components. You create static and dynamic components with development tools and use the Packaging Wizard to store them in the Mobile Server Repository. You create and store the application's database components in an object-relational database (Oracle Lite or Oracle). Examples of each component type include:
| Component Type | Example |
|---|---|
| static | HTML files, image files (such as GIF and JPG), HTML templates |
| dynamic | Java servlets, Java applets, JavaServer Pages |
| database | tables, snapshots, sequences |
Static components are HTML files that do not change, such as graphical elements (GIF files and JPG files), and textual elements (HTML files and templates).
Java applets, Java servlets, and JavaServer Pages (JSP) are dynamic components that create dynamic Web pages. Java applets, create a rich graphical user interface (GUI), while Java servlets and JSPs extend server-side functionality.
Java applets are small applications executed in the browser that extend the functionality of HTML pages by adding dynamic content. In the offline mode, the Java applets connect to the Oracle Lite database through the Mobile Client for Web-to-Go. In the online mode, the Java applets can connect directly to the Oracle8 or Oracle8i database through a thin JDBC driver. Alternatively, the Java applets connect to the Oracle database through the Mobile Server.
Web-to-Go simplifies the creation of dynamic Web pages by using Java servlets. Java servlets are platform-independent, server-side modules that can be used to extend the capabilities of a Web server. Written in Java, these modules are loaded to the Web server.
Web-to-Go generates dynamic Web pages using JavaServer Pages (JSP) technology, an extension of the Java Servlet class API. Developers use JSP to change a page's layout without altering its underlying content. JSP, which uses HTML and pieces of Java code, fuses presentation content (HTML and traditional editors) with business logic though its access of JavaBeans.
Snapshots and sequences are the two database components that Web-to-Go supports. The snapshot definition incorporates information about the table on the Mobile Server of which the snapshot was taken. Also, Web-to-Go executes custom DDL (Data Definition Language) statements, enabling the creation of such database objects as views and indexes.
The Mobile Client for Web-to-Go creates disconnected support for tables through its support for snapshots. On the client side, a snapshot is created for each database table. These snapshots refresh the data each time the client synchronizes with the Mobile Server. Web-to-Go propagates the data changes automatically.
Snapshot definitions can include a WHERE clause which limits the amount of data replicated to the client. These definitions are called snapshot templates. See Oracle9i Lite Administration Guide for more information about how to register snapshot templates. For more information on how snapshot templates and subqueries snapshots can enhance your applications, see Oracle9i Lite Administration Guide.
Sequences (used in many database applications) allow you to generate unique identifiers. You can use sequences to generate unique primary key values when inserting new records in a database table. This is very important when clients in disconnected mode insert new rows into tables. Replication uses the primary key values to identify records. Duplication of primary keys causes replication conflicts which must be manually resolved by the administrator. Because avoiding these conflicts is important, Web-to-Go provides a mechanism to ensure that sequence values generated in disconnected mode are unique (valid). To this end, Web-to-Go assigns each disconnected client a unique window of sequence values for each sequence.
Sequence numbers are from -2,147,483,648 to 2,147,483,647 in Oracle Lite and from -10^26 to 10^27 in Oracle. This allows for the creation of large windows of sequence values. For example, 10,000 users, each with a window of 10,000, use only 100,000,000 sequence values, which is approximately 5 percent of the available positive sequence values in Oracle Lite. See Oracle9i Lite Administration Guide for more information.
In addition to replication support for tables and sequences, Web-to-Go also executes custom DDL (Data Definition Language) statements on clients. You can use DDLs to create any database object, such as a view or a synonym. DDLs are part of Web-to-Go applications and are defined using the Packaging Wizard. Web-to-Go executes DDLs only once on each client when the client synchronizes the first time.
The database components can be accessed from the Java servlets through a JDBC connection. Because Web-to-Go creates and maintains the pool of JDBC connections, it is not necessary to create connections inside the servlet code. If Web-to-Go is running in online mode, the connection is to Oracle; if Web-to-Go is running in disconnected mode, the connection is to Oracle Lite. Web-to-Go assigns a connection object to the HTTPServletRequest object before processing the HTTP request using the Java servlet's doPost() or doGet() method. The connection is automatically returned to the connection pool upon completion of the HTTP request. Because a user may not get the same connection object for a subsequent HTTP request, the servlet must either commit or abort the transaction upon completion of the methods, doPost() or doGet(). Web-to-Go automatically rolls back any pending transactions before a connection object is returned to the connection pool.
Database connections are both application-based and session-based. For a given session, Web-to-Go maintains a single separate connection for each application. If an application runs multiple servlets simultaneously, those servlets use the same connection object. This may occur if the application uses multiple frames or if a user accesses the application with two separate browser windows. In addition, multiple windows that are part of the same browser share the same session. The same is true for multiple instances of the same browser. For example, starting Netscape twice on the same machine only results in one session. However, when the user runs both Netscape Navigator and Internet Explorer, the result is two different sessions.
It is common for applications to display different functionality depending on the type of user who is running the application. For example, an application may show different menu items depending on whether manufacturing managers or shipping clerks run the application.
You can accomplish this in Web-to-Go by defining application roles. The application behavior then changes depending on whether or not a user has a specific role.
In the above example, you can define the application role MANAGER. In your application code, where you generate the menu, you then need to check if the user has the role MANAGER, and display the correct menu items.
You use the Packaging Wizard to define application roles in Web-to-Go. You assign roles to users and groups through the Mobile Server Control Center. However, it is up to the application developer to determine and implement how the application should behave if the user has a specific role.
You can query the Web-to-Go user context to retrieve a list of the users' roles.
Web-to-Go handles HTTP requests for JavaServer Pages (JSP) in two ways:
After the Mobile Client Web Server receives an HTTP request for a JSP, it checks if both the corresponding JSP source file and class file exist. If the class file exists and is newer than the JSP source file, the Mobile Client Web Server loads the Java class and executes the servlet.
If the class file does not exist, or if it is older than the JSP source file, the Mobile Client Web Server automatically converts the JSP source file into a Java source file and compiles it into a Java class under the APP_HOME/_pages. After the JSP has been converted and compiled, the Mobile Client Web Server loads the Java class and executes the servlet.
After the Mobile Server or Mobile Client for Web-to-Go receives the HTTP request for a JavaServer Page, the corresponding Java class is loaded from the APP_HOME/_pages directory and is executed. Since both the Mobile Client for Web-to-Go and the Mobile Server assume that the corresponding class file exists, you must convert the JSP source file into a class file. Then, when deploying the application using the Packaging Wizard, you must include both the JSP source file and the corresponding class file. You can create the class files by using the Packaging Wizard tool, or manually by using the Oracle JSP (OJSP) command line translator.
List your JSP files in the the Files panel of the Packaging Wizard. Click the Compile button in the Files panel. The Packaging Wizard will locate all the JSP files that you listed and automatically compile all of them. The Packaging Wizard will add the compile class to the application package.
You develop Web-to-Go Java servlets with the Mobile Development Kit for Web-to-Go. The Mobile Development Kit for Web-to-Go simplifies the process of writing Web-to-Go servlets. Before using the Mobile Development Kit for Web-to-Go, you must first install it on the development client. The Mobile Development Kit for Web-to-Go contains a Web server called the Mobile Client Web Server that executes Java servlets. You can use the Mobile Client Web Server to run and debug Java servlets.
The Mobile Development Kit for Web-to-Go Web server is a scaled-down version of the Mobile Server and has the following limitations:
It contains no application repository. As a result, the Mobile Development Kit for Web-to-Go Web server loads all files and classes directly from the file system.
Security and access control are disabled.
Clients that connect to the Mobile Development Kit for Web-to-Go Web server cannot go off-line.
It provides connection management only to Oracle Lite. It connects the user to the schema SYSTEM in the Oracle Lite database webtogo.
You can access applications on the Mobile Development Kit for Web-to-Go Web server by performing the following steps:
To launch the Mobile Development Kit for Web-to-Go Web server, from a DOS prompt, type:
cd Oracle_Home\mobile\sdk\bin
wtgdebug.exe
Use your browser to connect to the Mobile Development Kit for Web-to-Go Web server using the URL http://machine_name:7070/. A page with icons appears. Each icon represents an application in the Mobile Client Web Server. Note that port 7070 is the default port for Web-to-Go debug. For more information, see the webtogo.ora file in Oracle_Home\mobile\sdk\bin\wtg.ora.
Click the icon of the application you want to access.
Web-to-Go uses servlets to handle HTTP client requests. Servlets handle HTTP client requests by performing one of the following tasks:
Creating dynamic HTML content and returning it to the browser.
Processing and submitting HTML forms using an HTTP POST request.
Servlets must extend the HttpServlet abstract class defined in the Java Servlet API. The following is a servlet example:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class HelloWorld extends HttpServlet
{
/**
* Process the HTTP POST method
*/
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
writeOutput("doPost", request, response);
}
/**
* Process the HTTP GET method
*/
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
writeOutput("doGet", request, response);
}
/**
* Write the actual output
*/
public void writeOutput (String method, HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
// set content type
response.setContentType("text/html");
// Write the response
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println("Hello World");
out.println("</TITLE></HEAD><BODY>");
out.println("<P>This is output from HelloWorld "+method+"().");
out.println("</BODY></HTML>");
out.close();
}
}
Web-to-Go provides four Java packages. The oracle.html and oracle.lite.html packages are both described in Appendix B, " Web-to-Go Java Packages". The oracle.lite.web.servlet and oracle.lite.web.applet packages are both described in the Mobile Server API. You can use the classes supplied in the packages to simplify the development of Java servlets.
oracle.html. This package provides class abstractions of all the HTML elements (HTML tables and form buttons), enabling you to create and manipulate HTML objects in the Java code easily. See "Using the oracle.html Package" in Appendix B, " Web-to-Go Java Packages" for more information.
oracle.lite.web.html. This package contains base classes you can extend to create customized Java servlets. These classes enable you to create HTML forms linked to database tables easily. The data is automatically loaded from the database and formatted in HTML. When the form is submitted, any changes to the data in the form are automatically reflected in the database. For more information, see Using the oracle.lite.web.html Package in the Mobile Server API. See also "Using the oracle.lite.web.html Package" in Appendix B, " Web-to-Go Java Packages" for more information.
oracle.lite.web.servlet. Servlets can use classes from this package to obtain user profile information. This package defines the OraHttpServletRequest class, which implements the HttpServletRequest interface from the Java Servlet API.
oracle.lite.web.applet. This package contains the classes to be used with Web-to-Go applets. It contains AppletProxy class which is used as a proxy for Web-to-Go applets making JDBC connection or communicating with a servlet on the Mobile Server . It also contains a few more classes which are used by the AppletProxy class to communicate with the Mobile Server. See Using the oracle.lite.web.applet Package in the Web-to-go API for more information.
Web-to-Go creates a user context (or user profile) for every user logged on to Web-to-Go. Web applications always run within the user's specific context. Servlets, which are always part of an application, can use the user context in which it is running to access the services provided by Web-to-Go. The user context can be used to obtain the following information:
The name of the user
The mode the user is running in (online or offline)
The application the user is accessing
The database connection
The roles the user has for this application
The name/value pairs stored in the registry for this user
Servlets can access the user profile through the standard java.security.Principal obtained through the getUserPrincipal method of the javax.servlet.http.HttpServletRequest class.
This object can also be obtained from the oracle.lite.web.servlet.OraHttpServletRequest, a subclass of the JavaSoft-defined javax.servlet.http.HttpServletRequest. Servlets can typecast the request parameter to the OraHttpServletRequest object and call the getUserProfile method to obtain the user profile object. For example:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// Retrieve the database connection from the User Profile,
// which can be accessed from the HttpRequest
OraUserProfile oraUserProfile = ((OraHttpServletRequest)ora_request).getUserProfile();
.
.
.
}
|
Note: Oracle recommends using thejava.security.prinicipal, as OraUserProfile will be deprecated in the next release of Web-to-Go.
|
Servlets can obtain a connection to Oracle8i from the UserPrincipal object
Connection conn = ((OraUserProfile) request.getUserPrincipal()).getConnection();
Servlets can open or create a new file in the application repository. Access to the Mobile Server Repository is provided through the servlet context, which can be obtained by calling getServletContext() from within the servlet. For example:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// Retrieve the servlet context
ServletContext ctxt = getServletContext();
// Open an input stream to the file input.html in the Mobile Server Repository
// All file names are relative to the application's repository directory
InputStream in = ctx.getResourceAsStream("input.html");
// Open an output stream to the file output.html in the Mobile Server Repository
// All file names are relative to the application's repository directory
URL url = ctxt.getResource ("output.html");
URLConnection conn = url.openConnection();
OutputStream out = conn.getOutputStream();
.
.
.
}
After you create the Web-to-Go servlet, you run the servlet.
Before you can access servlets from the browser, you need to register them with the Mobile Client Web Server. To register servlets, you first register the application and then add the servlets to it. (Web-to-Go allows you to register multiple applications.) When you connect to the Mobile Client Web Server from the browser, it displays a list of all registered applications.
The Mobile Development Kit for Web-to-Go includes the Packaging Wizard, a tool for registering applications and servlets. You can invoke the Packaging Wizard by typing the following at the command line:
c:\> wtgpack -d
Initially, you select whether to create a new application or to continue work on an existing application.
Figure 3-2 The Make a Selection Dialog Box
After you make your selection and click OK, the Application panel appears.
Figure 3-3 The Application Panel
For detailed instructions on how to use the Packaging Wizard, see Chapter 4, " The Web-to-Go Tutorial".
The configuration information for the Web server and Packaging Wizard is stored in the webtogo.ora file.
The file is located in the Oracle_Home\mobile\sdk\bin directory.
The webtogo.ora file contains the following parameters:
| Parameter | Definition |
|---|---|
| ROOT_DIR | The Mobile Server expands all file paths relative to its root directory. You can change the root directory by modifying the value of ROOT_DIR in the webtogo.ora file. The default value is Oracle_Home\mobile\sdk\wtgsdk\root. |
| PORT | The port on which the Web server listens. The default value is 80. The default value for the Mobile Client Web Server is 7070. |
| XML_FILE | The XML file that contains the application information. The Packaging Wizard creates and maintains the XML file. You can modify the XML file by using the Packaging Wizard. |
See the discussion of initialization parameters in Oracle9i Lite Administration Guide for more information.
Start wtgdebug.exe by performing the following steps.
From a DOS prompt, type:
wtgdebug
Use a browser to connect to the Mobile Client Web Server located at the URL:
http://machine_name:port
This displays the list of applications that are currently known to the Mobile Client Web Server. The Mobile Client Web Server retrieves this list from the XML file. By default, this list includes the sample applications Servlet Runner and Sample.
Select the application to debug. This launches a new browser window which you can use to step through the application.
|
Note: If you change and recompile your servlet, you need to restart the Web server. You can stop the Web server by pressing Control+C. |
Because the Mobile Client Web Server is written in Java, you can run it inside a Java Virtual Machine (JVM), instead of running wtgdebug.exe. Running the Mobile Client Web Server in the JVM enables you to debug Web-to-Go applications by running the Mobile Client Web Server inside a Java debugger. You can use the class oracle.lite.web.server.WebToGoServer to start the Java version of the Mobile Client Web Server.
Before you can use the Java version of the Mobile Client Web Server, you need to add the following to your CLASSPATH:
Oracle_Home\mobile\sdk\bin\webtogo.jar
Oracle_Home\mobile\classes\olite40.jar
Oracle_Home\mobile\classes\xmlparser.jar
Oracle_Home\mobile\classes\classgen.jar
Oracle_Home\mobile\classes\ojsp.jar
Oracle_Home\mobile\classes\jssl-1_2.jar
Oracle_Home\mobile\classes\javax-ssl-1_2.jar
Oracle_Home\mobile\classes\consolidator.jar
You must add the location of your application classes, such as
Oracle_Home\mobile\sdk\wtgsdk\root, to the CLASSPATH. See also "Step 5: Running the Application" from Chapter 4, " The Web-to-Go Tutorial".
The file RunWebServer.java demonstrates how to use the class oracle.lite.web.server.WebToGoServer to control and start the Mobile Client Web Server. This file is located in the following directory:
Oracle_Home\mobile\sdk\wtgsdk\src
To start the Mobile Client Web Server, perform the following steps:
Compile the Java file by using the following command:
javac RunWebServer.java
Run the Mobile Client Web Server with the following command:
java RunWebServer
You can set various properties of the Mobile Client Web Server dynamically using the method WebToGoServer.setProperty(). These values override the values in webtogo.ora. Properties that can be controlled are:
| Property | Definition |
|---|---|
| config_file | The configuration file to use. See also "The webtogo.ora File". |
| port | The port on which the Mobile Client Web Server listens. |
| debug | Enables debugging. Set to Yes if you want to view debug messages. |
| log_file | The debug log file. If specified, debug messages are sent to this file, otherwise the messages are displayed to the screen. |
| root_dir | The root directory. Overrides ROOT_DIR in webtogo.ora. See ROOT_DIR. |
For example:
WebToGoServer.setProperty ("config_file",
"d:\\orant\\webtogo\\bin\\webtogo.ora");
WebToGoServer.setProperty ("debug", "true");
WebToGoServer.setProperty ("port", "80");
You can also dynamically add servlets without using the Packaging Wizard. Use the following Java code to register the servlet class HelloWorld with the Mobile Client Web Server:
WebToGoServer.addServlet("HelloWorld", "/Hello");
The servlet is added to the default application, "servlet runner," and can be accessed by typing the following URL:
http://machine_name/servlets/Hello
The servlet returns the following HTML:
<HTML><HEAD><TITLE>
Hello World
</TITLE></HEAD><BODY>
<P>This is output from HelloWorld doGet().
</BODY></HTML>
You can create your own servlet that handles all HTTP requests for files with a particular file extension. For example, you can have a servlet ASPHandler that handles all requests that end in "asp".
You can register this handler with the Mobile Client Web Server using the method WebToGoServer.addMIMEHandler(), for example:
WebToGoServer.addMIMEHandler("text/asp", "asp", "ASPHandler")
Web-to-Go provides a registry that can be used to persistently store objects. These objects can be obtained inside your servlet code using the method OraUserProfile.getValue(). The Mobile Server stores the registry objects in the access control system. For the Mobile Client Web Server you can set these registry objects dynamically using the method WebToGoServer.addRegistryEntry(). This enables you to test applications that use the registry. For example:
// Add a registry name/value pair to the default application "servletRunner"
WebToGoServer.addRegistryEntry ("usercode", "1111");
// Add a registry name/value pair to the specified application.
WebToGoServer.addRegistryEntry ("TESTAPPLICATION", "code", "112");
In software development, debuggers are often used to examine code and fix bugs. With Web-to-Go, you can use a debugger to test applications containing Java servlets. By running these servlets inside a Java debugger, you can set breakpoints in the Java code, view the code, examine threads, and evaluate objects. You can debug Web-to-Go applications by using the WebToGoServer class inside a debugger. See "Configuring Oracle JDeveloper" for more information.
The Mobile Development Kit for Web-to-Go automatically creates a database connection to Oracle Lite. This database connection connects to the database schema SYSTEM. Within your servlet code you can obtain this connection from the HTTP request. See "Database Component Access" for more information. You can also connect to the Oracle Lite database directly using ODBC. Connecting to the Oracle Lite database directly by using ODBC is helpful for performing the following tasks:
Creating schema objects such as tables, view and sequences
Manually checking table contents
To connect to Oracle Lite, launch msql by typing the following syntax at a DOS prompt:
msql system/x@jdbc:polite:webtogo
Web-to-Go supports Java applets. For security reasons, Web-to-Go applets must communicate with the Mobile Server or the Oracle database by using a proxy class. The AppletProxy class acts as a proxy for Web-to-Go applets and provides the applet with the required methods for communicating with the Web-to-Go servlet or for making a JDBC connection. An instance of the AppletProxy should be created while instantiating the applet. Once the instance of the AppletProxy class is created, the AppletProxy object communicates with the Mobile Server and derives all of the required information to connect to the server or to make a JDBC connection to the Oracle8 or Oracle8i database.
The Web-to-Go applet extends the java.applet.Applet. When the init() method initializes the Web-to-Go applet, it creates an instance of the AppletProxy class by passing the Applet reference as parameter. Once you create an instance of the AppletProxy class, you can use different methods of the AppletProxy class for communicating with the servlet or for establishing a JDBC connection with the Oracle database. For example:
import oracle.lite.web.applet.*;
public class AppApplet extends Applet
{
public void init()
{
..
..
// Create Instance and pass Reference of applet as parameter
proxy = new AppletProxy(this);
}
AppletProxy proxy;
}
The applet can use the following methods to communicate with the servlet. Each method requires an instance of the AppletProxy class:
The applet can use the getConnection()method to establish a JDBC connection with the database.
The Web-to-Go applet is launched from an HTML page that contains the following tags:
<html>
<body>
<applet ARCHIVE="/webtogo/wtgapplet.jar" CODE="MyApplet.class" WIDTH=200 HEIGHT=100>
<PARAM NAME="ORACLE_LITE_WEB_SESSION_ID" VALUE="123">
</applet>
</body>
</html>
The AppletProxy class uses the value of the ORACLE_LITE_WEB_SESSION_ID parameter to obtain the session ID from the Mobile Server. The session ID is subsequently added to every request an applet makes to a servlet. You can write the HTML code in a static HTML page or you can generate it from a servlet.
Web-to-Go can automatically add the parameter to any static page containing the APPLET tag. For this option, you must change the HTML page's extension to .ahtml as demonstrated in the following syntax:
page_name.ahtml
When the client accesses the HTML page, a Web-to-Go system servlet adds the required <PARAM> tag for the ORACLE_LITE_WEB_SESSION_ID parameter to the HTML. For example:
<PARAM NAME="ORACLE_LITE_WEB_SESSION_ID" VALUE="123">
The Web-to-Go system servlet sets the VALUE attribute to your Web-to-Go session ID.
You can also dynamically generate the HTML page that contains the <APPLET> tag. When you generate the HTML page dynamically, you must add the session ID parameter manually. You can retrieve the sessionID information from the oraUserProfile as follows:
import oracle.lite.web.html.*;
import oracle.lite.web.servlet.*;
public class AppServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse resp)
{
PrintWriter out = new PrintWriter(resp.getOutputStream());
out.println("<HTML>");
out.println("<BODY>");
out.println("<APPLET ARCHIVE="/webtogo/wtgapplet.jar"
CODE='MyApplet.class' WIDTH=200 HEIGHT=100>");
// Add these lines to add one more PARAM tag in html page
// This code should be added in-between <APPLET> and </APPLET> tag
OraHttpServletRequest ora_request = (OraHttpServletRequest) req;
OraUserProfile oraUserProfile = ora_request.getUserProfile();
out.println(" <PARAM NAME=\"ORACLE_LITE_WEB_SESSION_ID\" VALUE=\""
+oraUserProfile.getAppletSessionId(req)+"\"> ");
out.println("</APPLET>");
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
}
You can develop Java applets that access the database using a JDBC connection. Once you create an instance of the AppletProxy class, you must use the getConnection()method of AppletProxy class to obtain a JDBC connection. The getConnection()method returns the JDBC Connection object.
You can use the getConnection() method to obtain a JDBC Connection. The getConnection() method determines whether the connection mode is online or offline and provides the correct database connection (Oracle8 for online mode and Oracle Lite for offline mode) to the user. For example:
import oracle.lite.web.applet.*;
public class AppApplet extends Applet
{
public void init()
{
..
..
// Create Instance and pass Reference of applet as parameter
proxy = new AppletProxy(this);
}
public java.sql.Connection getDataBaseConnection()
{
java.sql.Connection dBConnection = proxy.getConnection();
return dBConnection;
}
AppletProxy proxy;
}
The Web-to-Go applet holds the database connection even after the user exits Web-to-Go. The applet maintains the connection even if the user types a new URL in the browser address window or clicks the Back button. Web-to-Go application designers must ensure that their applications explicitly close the database connection when the user exits Web-to-Go. For example, you can close the connection by calling the
dBConnection.close() method referenced in the above code sample.
You can develop Java applets that communicate with Java servlets in the Web-to-Go environment. When a client first connects to the Mobile Server, the server generates a session ID and sends it back to the client. Each subsequent client request to the server contains this session ID. The Mobile Server authenticates the session ID before executing the client's request. When applets communicate with Web-to-Go servlets, each applet request must also contain this session ID. The setSessionId method in the AppletProxy class can be used to add the session ID to each applet request. The AppletProxy class also contains other methods that provide communication between applets and servlets.
|
Note: ThegetResultObject() and showDocument() methods can be used to communicate with the Java servlet. Use the setSessionID method if you want to create your own URL connection object.
|
Servlets must extend the HttpServlet abstract class defined in the Java Servlet API. The following example creates a servlet called HelloWorld that extends the HttpServlet class. The servlet sends the "Hello World" string to the applet that calls it as an object:
public class HelloWorld extends HttpServlet
{
public void doGet (HttpServletRequest request, HttpServletResponse response)
{
ObjectOutputStream out = new ObjectOutputStream (resp.getOutputStream());
Object obj = (Object) "Hello World" ;
out.writeObject(obj);
out.close();
}
}
The Web-to-Go applet uses the getResultObject method to communicate with the Web-to-Go servlet by passing the servlet URL and the ServletParameter object as parameters. The servlet responds to the applet request with a text string. The ServletParameter object can be either an object that can be serialized or a string containing name/value pairs. If the servlet accepts parameters, you can call the getResultObject method and pass the servlet parameters as one of the arguments. For example:
public Object getResult()
{
java.net.URL url = new URL("http://www.foo.com/EmpServlet");
String ServletParameter = "empname=John";
Object resultObject = proxy.getResultObject(url, ServletParameter);
return resultObject;
}
You can use the setSessionId method for adding a session ID to an existing URLConnection object. When you write the applet-servlet communication mechanism, call setSessionID(URLConnection) at the end of the method. The method adds a session ID to the passed URLConnection object and then returns the URLConnection object. For example:
public void YourMethod()
{
java.net.URL url = new URL("http://www.foo.com/MyServlet");
java.net.URLConnection con = url.URLConnection();
..
..
..
// pass the URLConnection to the method setSessionId
con = proxy.setSessionID(con);
// Do whatever you want to do with this URLConnection object
ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
out.writeObject(obj);
out.flush();
out.close();
}
The showDocument method displays any static document including those with a suffix of .html, .doc, .xls, or any other one defined by the user. The showDocument method retrieves these documents from the Mobile Server and displays them in the client browser. To display documents, a user must have access permissions for the document and must have the correct MIME type set in the Mobile Server. The showDocument(String relativeDocUrl, String winName) method displays the document in a different browser window identified by a window name that is passed in the winName parameter. The following method launches the help file from the server in a browser window named "helpWin".
public void showHelp()
{
String relativeDocUrl = "Help/HelpIndex.html";
proxy.showDocument (url, helpWin);
}
To show the document in the same browser window as your applet uses call showDocument(url) as shown below:
public void showHelp()
{
String relativeDocUrl = "Help/HelpIndex.html";
proxy.showDocument (url);
}
You can run Web-to-Go applications inside a Java debugger if you have already installed the Mobile Development Kit for Web-to-Go and a Java debugger, like Oracle's JDeveloper, Borland's JBuilder, or Visual J++. The example in this section assumes you are using Oracle's JDeveloper release 3.1, however, most of the information provided is also relevant to other debuggers.
The following sections discuss how to configure Oracle JDeveloper 3.1 to run the Sample 1 application that comes with the Mobile Development Kit for Web-to-Go.
To create a debug project:
Start JDeveloper.
Select File and then New Project. The Project Type (Step 1) screen appears.
Figure 3-4 The Project Type Screen
Enter the project's file name in the "What is the project's filename?" field.
In the second section of the Project Type screen ("What type of project would you like to select?"), select the radio button for empty project.
Click Next. The Project Options (Step 2) screen appears. Enter the following information:
| Field | Description |
|---|---|
| Default Package Name | Leave this field blank. |
| Project Source Path | Oracle_Home\mobile\sdk\wtgsdk\src\sample1\servlets |
| Output Directory | Oracle_Home\mobile\sdk\wtgsdk\root\sample1\servlets |
Figure 3-5 The Project Options Screen
|
Note: orant is the Oracle Home name on Windows NT systems. |
Click Next. The Project Information Screen (Step 3) appears.
Figure 3-6 The Project Information Screen
Enter information in the following fields:
| Field | Description |
|---|---|
| Title | Name of the project. |
| Author | Name of the author. |
| Copyright | Copyright date. |
| Company | Company name. |
| Description | A description of the project. |
Click Next. The Finish screen appears.
Check the options listed in the Finish screen. Click Back, if needed. Click Finish.
Figure 3-7 The Finish Screen
Configure the project properties for debugging. In the JDeveloper navigator menu bar, select Project and then Project Properties to view the Properties dialog box. Configure the following:
Target JDK Version:
Select 'Java version "JDK1.2.2_JDeveloper" ' as your target JDK version.
Source Root Directories:
Verify that this directory points to the root of the sources. It should be set to
Oracle_Home\mobile\sdk\wtgsdk\src\sample1\servlets.
Output Root Directory:
Set the output root directory to the directory
Oracle_Home\mobile\sdk\wtgsdk\root\sample1\servlets. The Mobile Server expects the class files to be in this directory.
Run/Debug Working Directory:
Set the run/debug directory to Oracle_Home\mobile\sdk\bin.
Figure 3-8 The Properties Dialog Box
JDeveloper 3.1 makes it easier to manage sets of .jar files by using libraries instead of CLASSPATH settings. Create a WTGSDK library with the following .jar files and add this library to your project.
Oracle_Home\mobile\classes\consolidator.jar
Oracle_Home\mobile\classes\ojsp.jar
Oracle_Home\mobile\classes\olite40.jar
Oracle_Home\mobile\sdk\bin\webtogo.jar
Oracle_Home\mobile\classes\servlet.jar
Oracle_Home\mobile\classes\xmlparser.jar
Oracle_Home\mobile\classes\classgen.jar
Perform the following steps to create a WTGSDK library:
Select the Libraries tab from the Properties dialog box.
Click Add.
Figure 3-9 Select a Java Library Dialog Box
Click New.
Enter WTGSDK.
Click "..." next to the Class Path field. The File dialog box appears.
Select the six .jar files noted above and then click OPEN.
Click OK.
|
Note: One of the standard JDeveloper libraries is called WTGServer. This library should not be used. |
Check the Include debug information box. Close the Properites dialog box by clicking OK.
To add the Sample1 files to your project:
Click the green plus sign in the JDeveloper navigator to add the Java sources to the project. The file dialog appears.
Select the Java source file Helloworld.java in the directory Oracle_Home\mobile\sdk\servlets, and click Open.
Add the file RunWebServer.java, which is located in the directory Oracle_Home\mobile\sdk, to the project.
Set one or more breakpoints in your code by right-clicking at the statement where you want to break. Select "Toggle breakpoint". The background of the statement becomes red, indicating the breakpoint.
Select the file RunWebServer.java in the Navigator window.
Choose Run/Debug "RunWebServer" from the menu to start the Mobile Server inside the debugger.
The Mobile Server is now ready for use. You can access it through your Web browser, by accessing the URL:
http://machine_name/
Where machine_name is the host name of the computer on which you are running JDeveloper.
When you run the Mobile Server inside the Java debugger and access it using a Web browser, performance may decrease. You can improve performance by:
Running the Web browser on a different machine.
Using the Task Manager to set the priority of the Web browser process to "LOW" (after you start the Web browser).
The Mobile Development Kit for Web-to-Go includes a set of APIs that comprise a basic Web-to-Go Workspace application. Developers can use these APIs to replace the standard Web-to-Go Workspace application with a customized version. These APIs provide such functionality as:
Login
Logoff
Synchronize
List User Applications
Change User's Password
For more information on the APIs used to build a customized Web-to-Go Workspace application, see the Web-to-Go API specification, which is located in the directory:
Oracle_Home\mobile\doc\javadoc\wtg
After developing the customized Web-to-Go Workspace application, the developer must create an Oracle Lite database called webtogo and load the newly created Web-to-Go Workspace application into it. The database acts as the Mobile Server Repository in the Mobile Client for Web-to-Go. For more information, refer to the file crclient.bat, which is included in the sample Web-to-Go Workspace application.
The developer must then create a webtogo.ora file for the Mobile Client for Web-to-Go that instructs the Mobile Server to use the customized Web-to-Go Workspace application. (Refer to "Webtogo.ora Parameters" for the correct parameter settings for the webtogo.ora file.)
The developer must then load the webtogo.odb file, which is created by the Mobile Client for Web-to-Go, the webtogo.ora file for the Mobile Client for Web-to-Go, and the Web-to-Go Workspace itself into the Mobile Server Repository. For more information, refer to the file crserver.bat, which is included in the sample Web-to-Go Workspace application.
The administrator must then modify the webtogo.ora file on the server to instruct the Mobile Server to use the new Web-to-Go Workspace application. (Refer to "Webtogo.ora Parameters" for the correct parameter settings for the webtogo.ora file.)
To instruct Web-to-Go to use a customized Web-to-Go Workspace application, you must set the following parameters in the [WEBTOGO] section of the webtogo.ora file.
| Parameter | Setting |
|---|---|
| CUSTOM_WORKSPACE | YES |
| CUSTOM_DIRECTORY | Repository directory of the Web-to-Go Workspace application. For example, /myworkspace. |
| DEFAULT_PAGE | The entry point of the Web-to-Go Workspace application. For example, myfirstpage.html |
| CUSTOM_FIRSTSERVLET |
The name of the servlet that you want to use in your customized Workspace. For example,
CUSTOM_FIRSTSERVLET= HelloWorld;/hello |
|
Note: Web-to-Go supports only one Workspace application per Mobile Server. |
The Mobile Development Kit for Web-to-Go includes a sample Web-to-Go Workspace application that illustrates how to use the Web-to-Go Workspace API. Developers can use this sample application as a starting point when developing their Web-to-Go Workspace applications. The sample Web-to-Go Workspace application is written using JavaServer Pages (JSP) and .html files. The JSP files are located in the "myworkspace/src" directory in the Mobile Development Kit for Web-to-Go. These files are compiled into class files that are copied into "myworkspace/out" directory. This directory also contains all .html files and image files that are used by the sample Web-to-Go Workspace application.
The Mobile Development Kit for Web-to-Go includes the following scripts that compile the JSP files, create the Oracle Lite database webtogo for the Mobile Client for Web-to-Go, and load all necessary files into the Mobile Server Repository.
| Script Name | Description |
|---|---|
| compile.bat | Compiles .jsp files and copies the class files to the "myworkspace/out" directory. |
| crclient.bat | Copies all files in the "myworkspace/out" directory into the webtogo.odb file. |
| crserver.bat | Copies all files in the "myworkspace/webtogo" directory to the Mobile Server Repository, including the webtogo.odb and webtogo.ora files. |
The Mobile Server Admin API enables an administrator to manage the application resources programmatically. Using the Mobile Server Admin API set, administrators can potentially create their own customized Control Center application to perform such functions as:
Creating and modifying users and user groups.
Granting and revoking application access for users and groups.
Granting and revoking application roles for a user.
Including users in and excluding users from group-level access to applications.
Assigning snapshot variables to the user.
Suspending and resuming applications.
Publishing a pre-packaged Web-to-Go application.
Customizing an application's underlying database connections.
For more information on using the API to build the Control Center, see the Web-to-Go API Specification, which is located in the directory:
Oracle_Home\mobile\doc\javadoc\wtg
|
Note: Administrators cannot use the open API set to change the basic properties of an application, such as snapshot definitions or servlets. This can only be done through the Packaging Wizard. For more information, see Oracle9i Lite Administration Guide. |
|
![]() Copyright © 2002 Oracle Corporation All rights reserved |
|