home client api server api protocol f.a.q. downloads

Invoke Java web application methods.

This guide shows how to create a Java web application and how to call its Java procedures or methods from PHP scripts.

Create a simple Java web application.

  • Download the zip file JavaBridgeTemplate.war to some local directory.
  • Open the zip file for example with "winzip" or "file-roller" and add itext.jar to its WEB-INF/lib folder.
  • Rename JavaBridgeTemplate721.war to ExcelCreator.war and copy it to your JEE deployment folder. Restart your JEE server, if necessary.
  • Wait a few seconds until the web application "ExcelCreator" appears.

Test your Java web application

  1. Create a PHP test script. For example:

    <?php require_once("http://localhost:8080/ExcelCreator/java/Java.inc");

    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=downloaded.xls");

    // create a 50x40 excel sheet and return it to the client
    $workbook = new java("org.apache.poi.hssf.usermodel.HSSFWorkbook");
    $sheet $workbook->createSheet("new sheet");

    for(
    $y=0$y<40$y++) {
      
    $row $sheet->createRow($y);
      for(
    $x=0$x<50$x++) {
        
    $cell $row->createCell($x);
        
    $cell->setCellValue("cell $x/$y");
      }
    }

    // create and return the excel sheet to the client
    $memoryStream = new java("java.io.ByteArrayOutputStream");
    $workbook->write($memoryStream);
    $memoryStream->close();
    echo 
    java_values($memoryStream->toByteArray());
    ?>

  2. Run your test script. For example with:
    php -n -dallow_url_include=On test.php >result.xls
  3. Your PHP script has called the web application "ExcelCreator" with a custom PHP script, to create a custom XLS file.
For further information please read the INSTALL.J2EE documentation from the documentation download file.