tags:

views:

156

answers:

3

i need to invoke a PHP method from java . can i do that with request dispatcher?

+1  A: 
Runtime.getRuntime.exec("php <your script name>">;
Visage
A: 

The request dispatcher is only meant to forward to (or include) another web resources in your J2EE web app.

If you want to bring user to a PHP page from a J2EE webapp, issue a redirect.

If you want to process results of request to a php page in your J2EE webapp, try HttpURLConnection or the like.

david a.
+3  A: 

You'll need to make a separate request as though it was to an external site, but that will essentially be a full web request. There is no way to call a single PHP function from within Java unless you've got a PHP interpreter in your JVM, which seems highly unlikely.

You probably want to write the PHP side like you would write for an AJAX interface (using JSON or some loosely defined XML) or a SOAP interface.

Ryan Graham
call over http is the way to go!
cherouvim