PHP 调用java

原文:http://php-java-bridge.sourceforge.net/pjb/webapp.php

 

如果需要使用自己编写的java类,只需把工程打成jar包,按照第二步加入到war包中即可。

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 JavaBridgeTemplate621.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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值