原文: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
- 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());
?>
- Run your test script. For example with:
php -n -dallow_url_include=On test.php >result.xls
- 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.