tags:

views:

246

answers:

4
+1  Q: 

PHP and J2EE

Can I use Struts as a backend and PHP as front end for a web application? If yes, what may be the implications.

A: 

What do you mean by backend and and frontend?

If you mean using Java for the admin side of your site and PHP for the part that the public will see then there is nothing stopping you.

The implications are that you will have to maintain two applications in different languages.

Hyposaurus
A: 

I think what you mean is you want to use PHP as your templating language and structs as your middleware (actions etc).

I would imaging the answer would be no, not without some kind of bridge between the structs session and the PHP.

If you say change x to 3 in java in a structs action, you couldn't just go <?php echo x ?> or whatever to get the value out, you would need to transfer that information back and forth somehow.

Submitting would be OK though, I would imagine.

Not recommended though.

SCdF
Actually, its not structs, its Struts Framework.
Adeel Ansari
+1  A: 

I don't know much about Java, but I remember running into Quercus a while ago. It's a 100% Java interpreter for PHP code.

So yes, you could have PHP templates on your Java app. Update: see Quercus: PHP in Java for more info.

Jordi Bunster
+2  A: 

The first thing to came to mind is Quercus (from the makers of the Resin servlet engine), as Jordi mentioned. It is a Java implementation of the PHP runtime and purportedly allows you to access Java objects directly from your PHP (part of me says "yay, at last").

On the other hand, while I have been itching to try a project this way, I would probably keep the separation between J2EE and PHP unless there was a real reason to integrate on the code-level.

Instead, why don't you try an SOA approach, where your PHP "front-end" calls into the Struts application over a defined REST or SOAP API (strong vote for REST here) over HTTP.

http://mydomain.com/rest/this-is-a-method-call?parameter1=foo

You can use Struts to build your entire "backend" model, dealing only with business logic and data, and completely ignoring presentation. As you expose the API with these URLs, and you are basically building a REST API (which may come in handy later if you ever need to provide greater access to your backend, perhaps by other client apps).

Your PHP application can be built separately (and rather thinly), calling into the REST API (perhaps using Curl) as if it would call into a database or some native PHP class library.

Anyway, that's what I'd do. But, if you do use Quercus, please post how it went.

Sam McAfee