public class phptest{ /**澳门新葡亰平台官网, * A sample of a class that can work with
PHP * NB: The whole class must be public to work,* and of course the
methods you wish to call * directly. * * Also note that from PHP the
main method * will not be called*/ public String foo; /** * Takes a
string and returns the result * or a msg saying your string was empty
*/ public String test(String str) {if(str.equals()) { str = Your string
was empty. ;}return str;} /** * whatisfoo() simply returns the value
of the variable foo. */public String whatisfoo() {return foo is + foo;}
/** * This is called if phptest is run from the command line with *
something like *java phptest * or *java phptest hello there */
public static void main(String args[]) { phptest p = new phptest();
if(args.length == 0) { String arg = ; System.out.println(p.test(arg));
}else{ for (int i=0; i args.length; i++) { String arg = args[i];
System.out.println(p.test(arg));} } } }
为了使用PHP测试这个JAVA类,我们创建一个phptest.php文件,内容如下: ?php
$myj = new Java(phptest); echo Test Results are b . $myj-test(Hello
World) . /b; $myj-foo = A String Value; echo You have set foo to b.
$myj-foo . /bbrn; echo My java method reports: b . $myj-whatisfoo() .
/bbrn; ? 如果你得到这样的警告信息:java.lang.ClassNotFoundException
error ,这就意味着你的phptest.class文件不在你的java.class.path目录下。
= (string) 12345678; or $myj-foo = 12345678;

You can leave a response, or trackback from your own site.

Leave a Reply