This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Calling simple PHP from Servlet or JSP  RSS feed

 
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
 
author
Posts: 4096
21
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
 
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
Posts: 4096
21
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
Boost this thread!