Calling PHP function from Java [duplicate]

依然范特西╮ 提交于 2019-12-24 02:53:08

问题


Possible Duplicate:
invoking a php method from java

Never came across with this situation before, so would like to understand / know how to go about this ?

Goal: Call php function from Java

Let's say Java code looks like this

pulic class Testing 
{

String userid;
String pass;
String url;
public static void main (String[] args )
{
   String value1 = checker ( userid, pass, url );
   String value2 = dataGetter ( value1 )
}

public static String checker ( String userid, String pass, String url);
{
  // Code to get authenticated 
}

public static String dataGetter ( value1 );
}

and PHP code looks like this

 <?php
    $url;
    $size;

    function dataGetter( value1, $size)
    {
     // code to get data from server
    }
 ?>

Will this be possible ? if so can someone explain me how deployment will work ? i.e java being deployed on tomcat and php on apache ?


回答1:


While they cannot communicate directly, you can have them communicate in the same way that a client browser can communicate with the server, which is to say, using ajax and javascript. Have one page generated through jsp or php (doesn't matter which) load via ajax a php page or a jsp page (or servlet). The result is whatever you want it to be in either case and in this way you can get information from either.

Alternatively, you can make a Java program that opens a connection to a php page and uses what gets returned if you don't want to use a browser.

Of course, I'm assuming you are in the strange circumstance where you cannot simply drop one technology in order to use the other or I would highly recommend that solution over this. However, as these things usually go, if you're too far into your project to back out now, then this will also work for you.




回答2:


Call the PHP via the command-line or via http using java.net.URL.



来源:https://stackoverflow.com/questions/13748137/calling-php-function-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!