|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
POWERBUILDER LINKS YOU MUST CLICK ON PB & Java
Building A JSP-JaguarCTS-PowerBuilder Bridge
Digg This!
This article demonstrates how to use JavaServer Pages (JSP) to manipulate PowerBuilder DataWindows. We'll create a Jaguar- CTS component in PowerBuilder and call it from JSP. Using techniques from our Hepek Dual Architecture Framework, we'll show how to Web-enable your existing DataWindows in a matter of minutes. We'll also visit a few technologies appropriate to this article and introduce each to the extent needed. We'll briefly go over Tomcat and the JSP container/engine, along with the associated setup. Once we've completed a fairly simple example, we'll introduce our Hepek DAF extension for JSP. The following tools will be used:
What Is JSP?
JSPs are files with a .jsp extension, executed in what is known as a servlet container or, in JSP context, a JSP container. Some of the older literature you may come across refers to a container as an engine. Basically, a JSP container is kind of a filter for JSP code, which is, in fact, Java code. The container receives a .jsp page that contains Java/JSP, JavaScript, or HTML code. The container filters out and executes Java/JSP code only. Each JSP page is compiled into the servlet by the container. Output of the container is pure HTML or other data that represents content. In our example we'll use Jakarta Tomcat as a container. A JSP container is a process that's initiated when the HTTP server starts. Only one container/process is used over the life span of the HTTP server that takes care of all servlet/JSP requests. This one instance of the container handles multiple requests by using Java threads, making a JSP/servlet execute faster than a Common Gateway Interface (CGI), for example, as there's no need for the operating system to create a new process for each request. Creating a new process is one of the more expensive tasks performed by the OS. JaguarCTS 3.6+ has its own built-in JSP container. We've avoided using it, however, as we determined that it's better to separate the servlet container and the application server. Future releases of JaguarCTS will provide a container as a plug-in to Web servers, thus reinforcing our opinion.
Object-Oriented Programming
JSP is often compared to Microsoft's Active Server Pages. Both JSP and ASP were created to support the development of dynamic content for browser-based applications. There are, however, many differences between the two. JSP technology embraces the write once, run anywhere philosophy of the Java architecture. When it comes to what the components can do on the client's machine, JSP/Java uses a sandbox approach and ASP/ActiveX uses a certificate approach. JSP is generally better for large projects, while ASP is convenient for smaller ones. The reason lies in the object-oriented nature of Java. Within enterprise-wide-sized projects, ASP has a tendency to result in spaghetti code, creating maintenance nightmares. If you've visited large commercial Web sites lately, you may have observed that many of them are transitioning from technologies like CGI, ASP, and ColdFusion to JSP. Some examples are Chase Manhattan Bank and the CitiBank Group. As far as the change from PowerBuilder to Java and JSP is concerned, we PB developers should have an easy transition. Concepts used in these technologies are strongly object-oriented and very similar to those of PowerBuilder. It should be noted that JaguarCTS provides support for both JSP and ASP. We strongly recommend JSP over ASP.
Setting Up Tomcat
In the examples presented Tomcat will serve as the Web server as well as the servlet/JSP container. We'll show you how to set it up to work with JaguarCTS. In case you get stuck in the Tomcat setup and need more details, please read the documentation that comes with it. If you still experience turbulence, visit the Dean Jones Web site at www.powerobjects.com and follow his instructions on connecting Tomcat and JaguarCTS. If you haven't downloaded Tomcat yet, visit http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.2.1/bin/ and download file jakarta-tomcat-3.2.1.zip. Extract the zip file (the default extract destination is C:\jakarta-tomcat-3.2.1). Once you extract the files, we recommend changing the default directory to C:\Tomcat for convenience. You'll need to set up two environment variables: TOMCAT_HOME and JAVA_HOME. Right-click on the My Computer icon on your desktop and select Properties from the displayed menu. Click on the Environment Tab and you'll see something similar to Figure 1. Enter values for TOMCAT_HOME and JAVA_HOME and create these two variables as shown in the figure. Now you can test Tomcat.
Figure 1: WinNT System Properties To start, go to %TOMCAT_HOME%\bin and double-click on startup.bat. If everything is okay, Tomcat will start and a DOS window will open. To shut Tomcat down, double-click on shutdown.bat. As mentioned earlier, we'll use Tomcat as the HTTP server as well as the servlet/JSP container. By default, Tomcat listens for HTTP requests on port 8080, the same port on which EAServer listens for HTTP requests. To avoid conflict between the two, modify either or both of them. As is often the case with computers and software, there's a trick to having the two work together without modifications. If you start Tomcat first and then JaguarCTS, you don't need to modify either, as the first one to occupy the port takes precedence. The second one started won't be able to receive HTTP requests. (This is just for your information and should never be used as part of your practice.) Now that we have two possibilities, we'll show you how to handle both.
Modifying an EAServer HTTP Listener
Modifying a Tomcat HTTP Listener
<!-- ========== Connectors =========-->In this section you'll need to change the parameter "port" value from the default "8080" to some other value. We'll set this value to "8888". This will make Tomcat listen for HTTP requests on port 8888. By default, Apache and IIS both listen for HTTP requests on port 80, Jaguar and Tomcat on port 8080, and JRun on port 8000.
Continuing with Tomcat
Creating/Defining a Database Now set the following properties: ODBC tab(Note: %SYBASE% is the path to the Sybase directory on your PC.) Return to the ODBC tab and click the Test Connection button. You should get a Connection Successful message in the pop-up window. Now we can use the HepekPBDJ data source to create a Connection Cache in JaguarCTS. Open up the Jaguar Manager and right-click on the Connection Cache Folder and select New Connection Cache. A new window opens, prompting for the cache name; call it HepekPBDJ. The Connection Cache Properties window will open. Set the properties as follows: General TabClick OK. The Connection Cache Properties window will close. Expand the Servers folder, then select and expand the Jaguar server. Right-click on Installed Connection Caches and select Install Connection Cache. A new window pops up, asking what you want to do. Click on Install an Existing Connection Cache button. The next screen comes up and prompts you to choose which connection cache to install. HepekPBDJ should be listed, so high-light/select it and click the OK button. Now you should see HepekPBDJ listed on the right-hand side of the screen. Right-click on it and select Cache Properties. The Properties window will appear. Click first on the Refresh button and then on the Ping button. If everything has gone according to plan, JaguarCTS will respond with: "Ping of HepekPBDJ ODBC Connection Cache succeeded."
Creating a JaguarCTS Component On the following screen click the Next button once again. The Wizard moves to a new screen and asks for the Component Name, which should by default be n_hepekpbdj. If it isn't, enter it. You can add a description, but it isn't required. Click the Next button. When a similar screen appears, enter the Jaguar Component Name, which should already read n_hepekpbdj. If it doesn't, enter it and click Next. The next screen asks for information about your JaguarCTS server. Enter your server IP or Server Name, depending on how you defined the JaguarCTS IIOP listener. Enter the IIOP port and login information for your JaguarCTS server, and click Next. We now enter the Package Name, which we'll identify as HepekPBDJ, and click Next. For the component type make sure that Standard Component is selected and click Next. For Component Instance Pooling we'll select Supported and click Next. For Transaction Support we'll select Not Supported. Make sure that Auto Demarcation/Activation is checked (see Figure 3). The next window defines how JaguarCTS creates the component interface. Don't check anything, and click Next. And don't check anything on the Debug and Live Editing screens either. When you click Next, a new screen comes up and asks for the name of the project. Change the existing default value, p_hepekpbdj, to p_hepekpbdj_jag_deploy, and click Next. On the next screen make sure that both "build consolidated .pbd" and "include unreferenced objects" are checked and click Next. Then click Finish. Now open up the library. The list of objects shown in Figure 4 should be contained within your hepekpbdj.pbl. In our next article we'll create functionality for our n_hepekpbdj JaguarCTS component. We'll also develop a HepekPBDJ.jsp page that will communicate with the n_hepekpbdj component. This JSP page will be able to handle an HTML String or ResultSet sent by JaguarCTS. We'll then introduce advanced JSP-JaguarCTS techniques, such as linkage and query, using our Hepek DAF .t
PBDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING POWERBUILDER / SYBASE NEWS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||