Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java as a backend and PHP as a front end

Tags:

java

php

There are already a few posts on SO discussion whether this architecture is a good idea or bad idea. For many reasons within our company including the existing programming talent, we've decided to use Java for the backend and PHP for the front end. Our objective is something like...

Java - Models/Controllers

PHP - Views

We're working on building a prototype of the interaction between Glassfish and Apache. One thing we're still working on is when a user visits http://domain.com/login.html and they login, that login will be sent to the Glassfish controller which exists somewhere like /login.java. We can do that no problem, the trouble is getting the view to be rendered at that URL.

Has anyone does this with PHP or any other technologies?

like image 560
Webnet Avatar asked Aug 24 '12 19:08

Webnet


People also ask

Can we use Java as front end and back end?

Languages used for the front end are HTML, CSS, and JavaScript while those used for the backend include Java, Ruby, Python, and . Net.

Can Java and PHP work together?

There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.

Should I use PHP or Java for backend?

In a nutshell: While comparing the Java vs PHP performance, Java is clearly a winner as it is faster and efficient than PHP to write enterprise applications. Like developers have to build mobile enterprise applications to streamline complex business processes and operations.

Can PHP be used for front end and back end?

PHP is a programming language for back end development only. JavaScript, in turn, was initially designed as a front end development language. But with the introduction of Node.


2 Answers

Have you considered setting up a soap/rest server in java and having PHP talk to that? I imagine that would be much simpler than what you're trying to achieve.

like image 196
George Avatar answered Oct 19 '22 15:10

George


I am sorry to bring this up but it seems like it would make things a lot simpler to stick with just one of these languages. If you are using PHP to add more logic into your view, it might be worth taking a look at Velocity. It allows you to access and create variables, iterate through lists, use conditionals, define macros, make method calls, etc. This seems like it might make things much cleaner. However, it is usually a good idea to try to keep as much logic out of your templates as possible.

If you would like to use PHP because that is what is required I would suggest taking a look at using web services to communicate. Take a look at Googles GSON library. It is really nice tool (on the java side) for mapping JSON Objects to your model (and vice versa).

On your front-end, it might also be worth taking a look at Backbone. It is a tool that makes it simple to mock up your model Objects and bind events to them, or add tie them directly to fields, etc.

like image 2
John Kane Avatar answered Oct 19 '22 16:10

John Kane