Recommended Posts

So I'm playing with a system that needs to be implemented using a web server (Apache, or others; it doesn't really matter which), PHP, and Java. However, I'm unsure of just how PHP and Java can actually work together. It seems to me that Java's servlets attempt to accomplish many of the same tasks that PHP does.
I want to use Java for the backend of the server and PHP for the frontend to generate pages that users see. I've read about experimental extensions for PHP to allow it to directly access Java classes, but I don't want to go that direction.
My question is, if I implement an HttpServlet and write out PHP as a response, is there a way to then have that PHP parsed by the web server as usual and sent to the client as pure HTML? Does this happen automatically? For example:

Note that I left out details for brevity.
If I sent out a response with PHP in it, would the web server be able to catch it, run it through PHP, and send pure HTML to clients?
PHP is really just being used to create dynamically generated pages and provide tools like a calendar. For that matter, does anyone know how to generate a request in PHP and forward it to a servlet?
Any insight is appreciated. Thanks!
P.S. I know there are a lot of questions in here, so links to sites with some answers are also appreciated. :-)

0

Share this post

Link to post

Share on other sites

Java Servlets require a servlet container (like Tomcat) to run and these operate somewhat differently from regular web servers. There's a common practice of running Tomcat on the backend and running a separate instance of Apache before that, but I don't think that even that setup will allow you to do what you're hoping to achieve. Quite frankly, I don't really understand why you want to combine PHP and Java like that. If you need a templating language for Java Servlets, try JSP, Struts or Java Server Faces. They do almost exactly what PHP does and they run from within a servlet container, so they can communicate effortlessly with servlets or beans.

0

Share this post

Link to post

Share on other sites

Actually, my team took a look at this today and decided to use the PHP Java Bridge extension. This'll allow our PHP to use our backend's Java API directly without the need to meddle with Servlets or (thank goodness) Struts or JSP!

Thanks again!

0

Share this post

Link to post

Share on other sites

This topic is 3576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.