JSP to Jaguar Using HTML DataWindow
Many developers are learning JSP and are seeing the benefits of developing with JSP. JSP offers you the ability to run on almost any platform with almost any Web server. This openness of JSP along with the strengths of Java programming language means you can do almost anything with JSP. Whether JSP is running in EAServer or from Tomcat, you need to connect to Jaguar to make calls. This can be done two ways. You can develop a Java Bean that can be declared in your page and make calls to Jaguar or you can code the connection right in your page. This exercise will show you how to code a connection to Jaguar straight from the JSP page.
We will code a simple PowerBuilder component that will run in Jaguar and return a HTML DW. Then we will code a JSP page to call the new Jaguar component.
This exercise will use Tomcat 3.2.1, see Tomcat to Jaguar for setting up Tomcat. Assuming you used the default install your server was loaded in C:\jakart-tomcat-3.2.1\. In the Tomcat to Jaguar we note the Web server runs on port 8080 by default. This port will conflict with Jaguars HTTP server. In the previous exercise we suggest changing the port to 8100. This exercise will use port 8100.
PowerBuilder Component
The PowerBuilder component is very simple. In my example I will create a component called n_sug in a package called sug. I will create a data object to retrieve all the records from the customer table in the demo database. See objects below.

The DataWindow
The DataWindow data object should select all the columns from the
customer table. Add 5 buttons as shown below and map the buttons to
the corresponding event.

There are a few key properties that must be set in your dataobject or they can be set in the script. First make sure the HTML DataWindow check box has been selected.

Second make sure you define the properties as follows and fill in the object name as obj.

The Component
The component will have one method of_html with the following arguments.

Add the code below to allow the HTML DW to work. As noted earlier you can set the DataWindow properties in the PowerScript to ensure they are set correctly. There is a name conventional dependence with all HTML DW. So you should consider setting these properties in the PowerScript function. In this example for convenience we set the properties when we built the DataWindow dataobject. IMPORTANT: Make sure EASDemo cache name is setup to allow cache by name.
transaction t
datastore ds
string sz_html
t = Create transaction
t.DBMS = "ODBC"
t.DBParm = "UseContextObject='Yes',CacheName='EASDemo'"
connect using t ;
ds = create datastore
ds.dataobject = "d_customer"
ds.SetTransObject( t )
ds.Retrieve()
ds.object.datawindow.htmlgen.browser = arg_browser
If len( arg_action ) > 0 Then
ds.SetHTMLAction( arg_action, arg_context )
End If
sz_html = ds.object.datawindow.data.html
disconnect using t ;
Return sz_html
You need to make sure the CacheName is correct for your server. Double check the cache name inside Jaguar Manager to see how you have the demo database defined. You can use any Connection Cache you want, as long as the DataWindow dataobject you created can retrieve data from the cache. Save the object as n_sug. After creating the DataWindow dataobject and component you need to deploy the objects to Jaguar. Build a project and deploy the component to Jaguar. In this example our component name is n_sug and our package name was sug. IMPORTANT: Make sure you include un-referenced objects when you deploy to Jaguar.
Create Java Stubs
The Java stubs are needed by the JSP engine to compile your JSP page. To export Java stubs you need to go into Jaguar Manager. Right-mouse-click on the sug package and select Generate Stubs/Skeletons This will pop up a box to specify where to export the Java stubs.

The dialog box allows you to specify the location to export the stubs. You want to select the check-box Generate Stubs then specify the location to place the code. The default location is %jaguar%\html\classes. We will use this default location because it is already in our classpath and this will make it easy to import the classes in our JSP page. See below. When Jaguar generates the stubs it will create a directory under %jaguar%\html\classes called sug and place all the Java source in this directory.

Compile Stubs
Compiling stubs is very easy. Simply jump to a DOS prompt and change to the new directory and compile. To change to the new directory type:
C:\>CD %jaguar%\html\classes\sug
This will change you to the new directory. Then type:
C:\>Program Files\Sybase\Jaguar CTS 3.5\html\classes\sug\javac –verbose
*.java

Writing the JSP Page
Using JSP version 1.0 we can import needed classes and use the classes in our script. The first four imports are classes needed to use CORBA naming service. The last import is importing the classes we exported from Jaguar. The import statements assume %jaguar%\html\classes is in the System ClassPath. The HTML DW needs three key pieces of information action, context and browser. Using these three pieces we can create a HTML DW from any DataWindow or DataStore. The code in the JSP page executes on the server and is referred to as server side script. The value returned from the call to Jaguar will include a lot of JavaScript or client side script and will execute in the user's browser. The JSP page below is very simple. After importing the classes needed, we request values from the Web server: the action, context and browser. Note the addition of "obj_" to action and context. This is the object name defined when we built our DataWindow dataobject. See source for page below. IMPORTANT: This page is referenced in our dataobject defined earlier so we need to make sure it's named the same: dwjag.jsp. Also be sure to change the NameServiceURL to your Jaguar location and set the correct User ID and Password.
Copy the file under C:\jakarta-tomcat-3.2.1\webapps\examples\jsp This is the examples directory and you can execute your JSP from here.
<html>
<head><title>Jaguar Test</title></head>
<body>
<%@ page import="org.omg.CORBA.ORB" %>
<%@ page import="org.omg.CosNaming.NamingContext" %>
<%@ page import="org.omg.CosNaming.NamingContextHelper"
%>
<%@ page import="org.omg.CosNaming.NameComponent" %>
<%@ page import="sug.*" %>
<%
String sz_action ;
String sz_context ;
String sz_browser ;
sz_action = (String)request.getParameter( "obj_action" )
;
if ( sz_action == null )
{
sz_action = "" ;
}
sz_context = (String)request.getParameter( "obj_context"
) ;
if ( sz_context == null )
{
sz_context = "" ;
}
sz_browser = (String)request.getHeader( "User-Agent" );
if ( sz_browser == null )
{
sz_browser = "" ;
}
n_sug iJagComponent = null;
String sz = new String("");
java.util.Properties props = new java.util.Properties();
props.put("org.omg.CORBA.ORBClass","com.sybase.CORBA.ORB");
props.put("com.sybase.CORBA.NameServiceURL", "iiop://jones:9000"
);
ORB orb = ORB.init((String[]) null, props);
try {
NamingContext context = NamingContextHelper.narrow( orb.resolve_initial_references("NameService"));
NameComponent[] name = { new NameComponent("sug/n_sug","")
};
SessionManager.Factory factory = SessionManager.FactoryHelper.narrow(context.resolve(name));
iJagComponent = n_sugHelper.narrow(factory.create("jagadmin","***"));
}
catch (org.omg.CORBA.ORBPackage.InvalidName aException) {}
catch (org.omg.CosNaming.NamingContextPackage.NotFound aException) {}
catch (org.omg.CosNaming.NamingContextPackage.CannotProceed aException)
{}
catch (org.omg.CosNaming.NamingContextPackage.InvalidName aException)
{}
try {
sz = iJagComponent.of_html( sz_browser, sz_action, sz_context );
}
catch (CTS.PBUserException aException) {}
out.print( sz );
%>
</body>
Run JSP Page
To run the JSP make sure Tomcat is running, Jaguar is running and call the URL. http://localhost:8100/examples/jsp/dwjag.jsp here.
