PHP Doku:: Java Beispiel - java.examples-basic.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige DienstePHP / Java IntegrationBeispieleJava Beispiel

Ein Service von Reinhard Neidl - Webprogrammierung.

Beispiele

<<Beispiele

PHP / Java Integration>>

Beispiel #1 Java Beispiel

<?php
// Instanziere Java Klasse java.lang.System in PHP
$system = new Java('java.lang.System');

// Beispiele für Propertyzugriffe
echo 'Java version=' $system->getProperty('java.version') . '<br />';
echo 
'Java vendor=' $system->getProperty('java.vendor') . '<br />';
echo 
'OS=' $system->getProperty('os.name') . ' ' .
             
$system->getProperty('os.version') . ' on ' .
             
$system->getProperty('os.arch') . ' <br />';

// java.util.Date example
$formatter = new Java('java.text.SimpleDateFormat',
                      
"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");

echo 
$formatter->format(new Java('java.util.Date'));
?>

Beispiel #2 AWT Example

<?php
// This example is only intended to be run as a CGI.

$frame  = new Java('java.awt.Frame''PHP');
$button = new Java('java.awt.Button''Hello Java World!');

$frame->add('North'$button);
$frame->validate();
$frame->pack();
$frame->visible True;

$thread = new Java('java.lang.Thread');
$thread->sleep(10000);

$frame->dispose();
?>
Notes:


2 BenutzerBeiträge:
- Beiträge aktualisieren...
anto dot justus at gmail dot com
10.06.2009 19:00
php java 

The PHP code here is simple and straight forward. It is not
 OOP. But you probably got enough of that while doing the
 Java code.

<?php

java_require
("F:\\wamp5\\www\\classes\\");
$obj = new Java("hello");

// Call the "sayHello()" method

$output = $obj->SayHello();

echo
$output.' this text in PHP

'
; // Displays (so this comes from the class!)

// Call the "SayNumber()" method

$output = $obj->SayNumber();

// Displays (so this comes from the class!)
echo $output.' is a lucky number';

//Because the JVM caches everything we want reset while
 
playing with the code. Otherwise the

// a cached version of the same class file will be used
rather than the new one

echo "
Resetting back-end to initial state\n"
;

// suppress the warning message from the use of reset.

@java_reset();

?>

That's it. Now browse to the PHP page and you should get
 the results shown below.
anto dot justus at gmail dot com
10.06.2009 18:08
Session sharing with php and java
------------------------------------------

<?php require_once("java/Java.inc");
$session = java_session();
?>

<HTML>
<TITLE>PHP and JSP session sharing</title>
<BODY>
<?php

if(is_null(java_values($session->get("counter")))) {
 
$session->put("counter", 1);
}

$counter = java_values($session->get("counter"));
print
"HttpSession variable \"counter\": $counter<br>\n";
$session->put("counter", $counter+1);
?>
<a href="sessionSharing.jsp">JSP page</a>
</BODY>
</HTML>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)