• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling simple PHP from Servlet or JSP

 
Renato Losio
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I have a jsp + servlet web app. I have to problem when I need to bridge to external technologies:

From the user registration page I would like to call a PHP script to send a message to the user when the process is completed. Note that the script is already available and I need to pass the phone number as a string. Is there a quick solution from the JSP page? I don't need to control the flow or catch any error, just call the sendMessage(String phoneNumber) script.

I guess a bit more complex, I don't know if a php-bridge is required. Same as above but I need to catch a return value from the PHP script. The validateCode(String phoneNumber) is pretty simple. It may return a integer code (from 1 to 5) and I would like from a servlet - or eventually a JSP - to handle the code and do some logic.

Any idea where to start? Any useful link?

Thanks.

Renato
 
Scott Selikoff
author
Saloon Keeper
Posts: 4010
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's really no such thing as a Java/PHP bridge, but these technologies are malluable enough that connecting them is pretty simple.

For example, one way to connect them in the context of a web environment is to have them make http calls to each other. You can restrict external people from doing this by having the php/jsp check to make sure the person executing the page has a local ip address. The advantages are that the programs never look at the internal structure of each other and therefore you can swap in JSP-to-JSP communication or PHP-to-PHP communication if you get rid of one of the technologies.

The other option is to have them drop to command line. For example, calling Runtime.exec() in java to run a php script. This is usually very fast but it might require a tighter coupling than the previous method in that your php calls may be extremely machine sensitive.
 
Renato Losio
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Scott,

many thanks for your prompt and detailed reply.

I will give both the options a try and see which one suits better my web app. Looks like I can call (quite) easily the PHP script but I won't be able to collect what I have back from the call. Is my assumption correct?

Cheers,

Renato
 
Bram Maes
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not really an expert in this, but isn't it possible to execute a JavaScript that redirects to the PHP page, and use a GET to pass the phone number ?

And maybe you could use the same to get output from the php page ?(and redirect vs jsp)
[ October 20, 2006: Message edited by: Bram Maes ]
 
Scott Selikoff
author
Saloon Keeper
Posts: 4010
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bram Maes:
I'm not really an expert in this, but isn't it possible to execute a JavaScript that redirects to the PHP page, and use a GET to pass the phone number ?



Eh, its never a good idea to base your primary logic (and communication) in javascript. Its not robust enough. Besides, I don't see why the javascript is necessary when PHP and Servlets can connect to each other directly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic