´¿java PHPÒýÇæ——Quercus
ÓÉÓÚ¹«Ë¾ÏîÄ¿µÄÐèÒª£¬×î¾ÔÚÑо¿QuercusÒ»¸ö´¿javaµÄphpÒýÇæ¡£ÏîÄ¿ÕâÁ½¸öÐèÒª×öµÄ¾ÍÊǽ«¸ÃÒýÇæ²Ã¼ô£¬×öÒ»¸öÏà¶Ô°²È«µÄ°æ±¾£¬Ìṩ¸øISVʹÓã¬Í¬Ê±£¬ÔÚÒýÇæÖÐÌṩĬÈϵĽӿڹ©µ÷Óá£ËùÒÔÏÈÑо¿ÁËһϣ¬ÔÚQuercusÒýÇæµÄÖ§³ÖÏ£¬PHPÈçºÎÓëjava¼¯³É¡£
ÒÔÏÂÊÇѧϰµ½µÄ¼¸µã£º
1¡¢Èç¹ûʹÓà Resin-IoC/WebBeansÀ´×éÖ¯Ó¦ÓõķþÎñµ½½Å±¾ÖУ¬ÄÇô½Å±¾ÖоͿÉÒÔÖ±½Ó»ñÈ¡µ½ÅäÖõķþÎñµÄµ¥ÀýʵÀýµÄÒýÓã¬Ê¹Ó÷½Ê½ÈçÏÂ
<?php
$demo_manager = java_bean("DemoeManager");
$demo = $demo_manager->findData("demoId");
foreach ($demo->getDatas() as $data) {
echo $data . "\n";
}
?>
2¡¢ÁíÍâÒ»ÖÖ¿ÉÒÔͨ¹ýnew Java()·½Ê½£¬ÒÔclassÍêÕûÃû³ÆÒÔ¼°¹¹Ô캯Êý²ÎÊý×÷Ϊ²ÎÊýÀ´Éú³É¶ÔÓ¦µÄjava ¶ÔÏó£¬ÀýÈç
<?php
$a = new Java("java.util.Date", 123);
echo $a->time;
?>
3¡¢Quercus»¹Ö§³Ö£¬ÀàËÆÓÚjava µÄÒýÓ÷½Ê½£¬¼´£¬ÔÚPHPÖÐʹÓÃimportÓï¾äÒýÈëclass£¬Ê¹ÓÃnew¹Ø¼ü×ÖÀ´´´½¨¶ÔÏó¡£
<?php
import java.util.Date;
$a = new Date(123);
echo $a->time;
?>
Èç¹ûÊÇʹÓÃResin¿ò¼Ü£¬»á×Ô¶¯¼ÓÔØ WEB-INF/classes/classname.phpÖÐÅäÖõĵÄclass¡£
4¡¢ÔÚQuercusÖУ¬PHPµÄÓï·¨ÓÃÓÚ¼¤»îjava¶ÔÏóµÄ·½·¨£¬ÏÂÃæ˵Ã÷Ò»ÏÂͨ³£µÄ·½·¨µ÷ÓúÍÊôÐÔµÄgetºÍset
<?php
import java.util.Date;
$a = new Date(123);
echo $a->getTime(); # calls getTime()
echo $a->setTime(456); # calls setTime(456)
echo $a->time; # calls getTime()
$a->time = 456; # calls setTime(456)
?>
5¡¢ÔÚQuercusÖУ¬javaÀà±»ÒýÈëÁË£¬¾²Ì¬·½Ê½ºÍ¾²Ì¬ÊôÐÔÊÇ¿ÉÒÔ·ÃÎʵÄ
<?php
import java.util.Calendar;
$calendar = Calendar::getInstance();
var_dump($calendar);
?>
»òÕßʹÓÃnew java_class()·½Ê½»ñµÃclass¶ÔÏó
<?php
$class = java_class("java.lang.System");
# System.in
$in = $class->in;
# System.currentTimeInMillis();
$time = $class->currentTimeInMillis();
?>
6¡¢¹ØÓÚjava¶ÔÏóÖеķ½·¨ÖØÔØÎÊÌ⣬PHP±¾ÉíÊDz»Ö§³Öº¯ÊýÖØÔصģ¬¶Ô²ÎÊý¸öÊýµÄÖØÔØÖ§³ÖµÃ»¹²»´í£¬µ«ÊDzÎÊý¸öÊýÏàͬ£¬²ÎÊýÀàÐͲ»Í¬µÄÖØÔØ
Ö§³ÖµÃ¾Í²»Ì«ºÃÁË¡£ÎÒ¾õµÃÊÇÓÉÓÚPHP±¾ÉíËùÀàÐÍÓйء£±ÈÈçÏÂÃæµÄ¶¨ÒåµÄjavaÀà
import com.caucho.quercus.module.Abs
Ïà¹ØÎĵµ£º
³õѧPHPµÄʱºò£¬ÎÒÃǾ³£±»PHPµÄ¾ø¶Ô·¾¶ºÍÏà¶Ô·¾¶ÅªµÄÔÎͷתÏò¡£Â·¾¶ÎÊÌâ¾³£µ¼ÖÂinclude¼°requireÃüÁî²»ÄܼÓÔص½Ö¸¶¨µÄÒ³
Ã棬´Ó¶øµ¼ÖÂWeb³ÌÐòÔËÐдíÎó¡£±¾ÎĽ«¸ú´ó¼ÒÒ»Æð̽ÌÖÒ»ÏÂPHP·¾¶ÎÊÌâµÄ³£Óýâ¾ö·½°¸¡£
ÏÂÃæÎÒÃÇÏÈ×öÒ»¸ö¸ö¼òµ¥µÄʾÀý:
ÉÏͼÊÇÒ»¸ö¼òµ¥WebÏîÄ¿µÄ½á¹¹Í¼,ÆäÖи÷ÎļþµÄ´úÂëÈçÏÂ: ......
ÒªÔÚJavaÖлñµÃijһ±äÁ¿µÄËø£¬±ØÐëÔÚ´úÂëµÄÊ×β¶þ¶Ë¼ÓÉÏsynchronized¹Ø½¡×Ö£¬Ö¸Ã÷ÐèÒª»ñµÃËøµÄ¶ÔÏó¡£Ò»µ©Ï߳̿ªÊ¼Ö´ÐÐsynchronized¿éÖеĴúÂ룬Ëü¾Í»ñµÃÁ˶ÔÕâÒ»¶ÔÏóµÄËøµÄ¿ØÖÆȨ¡£Í¬Ñù£¬Ò»µ©Ïß³ÌÒѾÀ뿪ÁËsynchronized¿é£¬ËüÒ²½«ÊÍ·ÅÕâÒ»¶ÔÏóµÄËø¡£ÎÒÃÇÒѾ֪µÀ£¬C#Ò²ÓÐÒ»¸öÏàËƵı»³Æ×÷lockµÄ¹Ø½¡×Ö¡£³ýÁËlockÕâ¸ö¹Ø½¡×Ö ......
ÖØÔØ£º·½·¨ÃûÏàͬ ·µ»ØÀàÐͺͲÎÊýÖÁÉÙÓÐÒ»Ïͬ£¨²ÎÊý°üÀ¨ÀàÐÍ ºÍ ÊýÁ¿£©
ÖØд£º·¢ÉúÔÚ×ÓÀà ·½·¨Ãû ·µ»ØÀàÐÍ ²ÎÊý¶¼Ïàͬ Ö»ÊǰѸ¸ÀàµÄ´Ë·½·¨ÖØÐÂд¶øÒÑ
Ò»Ö±ÒÔÀ´ÎÒ¶ÔFacther f = new Son()ÕâÑùµÄÒýÓñäÁ¿ÒýÓÃ×ÓÀàµÄʵÀý¶¼²»ÊǺܶ®¡£
»¹ÓоÍÊÇÏòÉÏÏòÏÂתÐÍ
È磺Animal animal = new Dog() // ÒýÓñäÁ¿ÒýÓÃÁËÀ´×Ô×ÓÀàµÄÊ ......
JAVAµ÷ÓÃMYSQL´æ´¢¹ý³Ì
¹¤³ÌÊÓͼ£º
´úÂëÇåµ¥£º
myconn.java
package org.apache.sh_mysql.test;
import java.sql.*;
public class MyConn {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost/test?useUnicode=true&characterEn ......
phpÁ¬½Ómysql²âÊÔ´úÂ룺
$link=mysql_connect('localhost','root','123456');
if(!$link) echo "ʧ°Ü!";
else echo "³É¹¦!";
mysql_close();
?>
ÔËÐдúÂë³öÏÖ£ºCall to undefined function 'mysql_connect()'… ʧ°Ü
°Ù¶ÈÕÒµ½½á¹ûÊÇPHP+MYSQL »·¾³Ã ......