|
It worked! A PHP script running in an Apache server on a W2K machine can use the program execution functions and Toolbox for Java to access iSeries resources. (My previous problem was due to corrupted JavaSoft keys in my registry.) I'm including some 'hello iSeries' code below. First, however, a few notes. Using the program execution functions to call Java programs has limitations. Output from the Java program goes straight to the browser using the PHP 'system()' function, which means the Java program called by the 'system()' function needs to format the output for display in a Web page. Output from the Java program can go into a PHP variable using the 'shell_exec()' function. The Java program could again format the output, or the PHP script could parse the variable and format. Using CSS or XML could help gain better control of output display using stylesheets. But I definitely would not try to build an e-commerce store using this approach. I see this approach as better suited to things like simple report submissions, simple batch job requests, and simple database queries. You would probably have greater flexibility using the Java integration methods mentioned in the PHP manual. The issues with these methods are: (1) you have to rebuild (recompile) PHP on your own windows machine to get the Java extension to work, and (2) you have to run an application server such as Tomcat or WebSphere to integrate PHP with Servlets. I'm not really interested in doing either of these things at the moment. Okay, here's the code. I used two PHP scripts to demonstrate the Java call works from an included PHP script. Here's a PHP script named helloiseries.php: <h2>Java Link Hello iSeries</h2> <?php require('http://localhost/php/jobs/javalink3.php'); ?> Here's the javalink3.php script: <p>Starting the javalink3 PHP script.</p> <?php $java = shell_exec('java JavaLink3'); if ($java == 1) { echo('The CL program was not called.'); } else { echo('The CL program was called.'); } ?> You could also have used the 'system()' function or the 'exec()' function. Here's the JavaLink3 source code: import com.ibm.as400.access.*; public class JavaLink3 { public static void main (String args[ ]) { try{ String system="myiseries"; String name="myname"; String password="mypassword"; String command="CALL PGM(MYLIB/JAVALINK3)"; //Create a connection to the iSeries. AS400 oursystem = new AS400(system, name, password); //Create and run the command. CommandCall submitCommand = new CommandCall(oursystem); submitCommand.setCommand(command); submitCommand.run(); //Return a value of "0" to indicate no errors. System.out.println("0"); } catch (Exception e) { //Return a value of "1" to indicate an error. System.out.println("1"); }//end try-catch }//end main }//end class Of course, if you want to call a program, it would be better to use the program call classes or PCML. But the CommandCall class works and can be used for other CL commands. Here's the code for the CL program MYLIB/JAVALINK3: STRPGM:PGM SNDMSG MSG('The Javalink3 program ran + successfully.') TOUSR(MYNAME) ENDPGM:ENDPGM Make sure your PATH environmental variable points to your Java Runtime Environment and your JavaLink3.class and jt400.jar files are in directories listed in the CLASSPATH environmental variable. Point your browser to the helloiseries.php page. You should see a message appear in your iSeries message queue and a message about the CL program in the Web browser. Later, Kelly __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.