Is it possible to build a Java web application which has a PHP front end ?
I want all my web pages to be coded in PHP. Most of them will be forms.
I want all the data submitted by a form to go to a Java Code.
I want to do all manipulation in back end and all rendering of web content on the front end.
This is just a general question as I was probing for different options for my java web application.
You might also want to take a look at php-java bridge
A web application, by definition is already a frontend (or at least includes it).
If you meant a PHP webapp built on top of a Java backend, sure, that's possible. If you use SOAP or REST for communication between the layers, it's actually relatively easy. The only drawback compared to a pure Java (or pure PHP) app would be the overhead of those protocols, so you have to be careful to avoid too fine-grained service interfaces.
It depends on where the two meet. You could have, for example, have Java backend and PHP frontend communicating via web services. I however see no benefit in such a combination.
You can use Quercus, a Java implementation of PHP, to run PHP from within Java (and thus have easy access to Java classes).
According to your edition, it looks like you don't need PHP at all. You confused it with HTML.
Yes. You can build a java web-application which has php front end.
it is possible even with C++ backend. but why?
Related
I have an enterprise Java web application deployed in tomcat.
I am looking for ways to integrate a HTML & JS UI with the mid tier java code. So far, from looking around I have read that there are two ways to do this which fit my requirements :
1) DWR - Direct web remoting
2) Use REST web services.
I am not sure which approach to use.
Edit: What is the advantage of using DWR over a rest WS design?
Is there a better approach available? Some people asked me to have a look at GWT, but I am not sure if these are scalable.
Edit 2: I will most likely be using dojo for the UI development(Works well with REST/DWR??), and I want to keep the java code chages minimal. I understand that by using web services, I would have to write an additional WS client layer on top of the existing java code.
Also, the usual enterprise needs, performance, scalability, etc.
Ok so you're building a web client frontend to your java backend, there are a few ways to go about this:
You want to use java standards as much as possible, preferably living in the java EE world: JSF. You will need some knowledge of HTML, XML and perhaps even javascript (though limited). Personally I have had a pretty buggy experience with JSF+richfaces to the extent that I don't use it anymore.
You are very well acquainted with java desktop application development but don't know much about javascript: vaadin: it allows you to write plain java using desktop application terminology which will be compiled to javascript. Currently I am working on a big vaadin project and it is very nice to be working with pure java in eclipse, the downside is however that you are far removed from the actual frontend, so tweaking can be tricky. Additionally everything is stored in sessions (afaik) and scales poorly.
You are primarily a frontend person with unrivaled javascript skills: use a REST interface in java and a pure js/html/css frontend. Personally I think this is the cleanest design and I have designed a few of my own applications like this. The downside is that managing large javascript projects tends to be hard because...well...javascript sucks. The upside is that this will always be the fastest most lightweight option available to you.
Ideologically I would definitely suggest the last approach but this can be hard for large projects. If you have the hardware to throw at it, vaadin is a nice option. My JSF 2 experience was a bit disappointing due to the bugs in (necessary) third party libraries like richfaces.
PS: I have never heard of DWR but the last stable release seems 2 years old and all it seems to do is expose java code as javascript methods which can be better handled with a REST interface.
Open interface standards like REST and SOAP make it easy to build code to consume these services if you are using frameworks to build a REST Client and a SOAP client code respectively. But the point is that you need to have this client code to make calls to these services.
DWR on the other hand, generates this client code. Your java classes are ready to be called (like you would do in Java).
I am about to start developing a private TODO website (that later will be extended to Web applications). I am unsure what framework to use. I have read about GWT and PHP frameworks such as Yii. What advantages do each one have over another.
Background
- experience in Java
- got an apache web host that supports php
Doubts:
Would developing in GWT mean that refactoring would be easier than developing in PHP (especially since you can use Eclipse)
seems like PHP frameworks such as Yii design objects for you once you create database layout ... can this be done with GWT?
Thanks!
One big difference I haven't seen mentioned in the question or answers/comments is that Yii is a server-side framework, which runs entirely on your own/hosted server, whereas GWT compiles to JavaScript, and is therefore runs in the client's browser only. These two offerings (and ideas) serve very different purposes, and can be used together.
When using GWT to build the client, the server can be built using any tool desired, so long as it exposes data to the JS-based client. That can be in the form of JSON or XML, or some other data encoding (GWT's built in RPC, for example, can pass complex object graphs to and from a Java servlet container).
If you were to use them together, Yii could be used to create PHP objects from the database schema/layout, and to build the various rules for authentication/authorization so the client can read and write data. GWT could then be used to build a client which reads and updates that data, making calls to services exposed by Yii/PHP code.
If you like Eclipse you can certainly stay with Eclipse and still develop in PHP. The PHP tools from eclipse.org are very good and the IDE plugin from Aptana is even better.
Regarding Yii vs GWT, it really depends on your language of choice. If you are highly proficient in Java and really like the strong typing of the Java language then GWT is a good choice (although there are certainly other choices that keep you in the Java world such as Tapestry). PHP frameworks vary quite widely in how much they embrace OOP and concepts such as creating your business objects based on your database. Yii definitely stands out as a framework due to the code generation capabilities built in. That will definitely help you if you're getting started with PHP.
I have just been looking at the GWT and i am impressed by what i have seen but i do not really understand how it is used to when creating web applications.
For example, when im programming in PHP or JSP creating a simple app that lets users register, adds the detailes to a database and then allows them to login is pretty simple but i was wondering how GWT does this?
When doing this in GWT, would GWT widgets be used to construct a frontend(client) that accepts user input and then sends it to a server which is written using pure Java, the Java then does all of the data processing and database interfacing?
If my understanding is correct, is GWT just a way to write javascript frontends in an easier way?
Have you looked into the GWT Overview? I think this line explains it the best:
The GWT SDK contains the Java API
libraries, compiler, and development
server. It lets you to write
client-side applications in Java and
deploy them as JavaScript.
Basically, you write your code in Java, all the while using the GWT to create complex UI's, etc. When you "compile" it, it is highly optimized JavaScript that translates well to multiple browsers, including web platforms.
Whatever language you want to use server-side does not matter - ASP.NET, PHP, etc - it will all work with GWT because GWT is, ultimately, JavaScript.
Basically, Google is trying to make it simple to develop web applications in a familiar language, and doing all the underlying work for you. I'm sure there is someone else who can further expand on the capabilities and advantages of GWT, but I hope this helps!
Exactly. "In the end, it's just JavaScript", you can "Use the backend language of your choice"
Have you experience of integration of php and Java? I've written a class in Java "Hello". Now I want to call its method from php when I create an instance of this class from php with
$obj = new Java(Hello);
Then it gives me fatal error. I've tried many times to setup php ini variables etc but I couldn't find anything. Please advice me how can I set it up.
Thanks in advance
Reference: http://php.net/manual/en/book.java.php
Have a look at:
PHP-Java Bridge
The PHP/Java Bridge is an
implementation of a streaming,
XML-based network protocol, which can
be used to connect a native script
engine, for example PHP, Scheme or
Python, with a Java virtual machine.
It is up to 50 times faster than local
RPC via SOAP, requires less resources
on the web-server side. It is faster
and more reliable than direct
communication via the Java Native
Interface, and it requires no
additional components to invoke Java
procedures from PHP or PHP procedures
from Java.
Could it be you are just missing the quotes around the Java Class? Also make sure you actually do have a Java VM on the machine you are trying to run the code on and make sure you have properly set up the config options. Also, the Java extension is a PECL extension and has to be installed. It is not part of the native distribution. Furthermore, the extension is considered unmaintained and dead, so you might want to have a look at the JavaBridge suggested elsewhere. Zend Server also brings a JavaBridge.
Check out this article: http://www.devshed.com/c/a/PHP/Using-PHP-with-Java/
They say it's possible (and how to do it). I've never done it, so I can't vouch for it...
In my experience the best way to interact between Java and PHP is through a WebService layer. NuSoap for PHP is very good, and you can consume the webservice in Java to create a stub that will build the request/response object.
There are many ways few are:
PHP Java Bridge
Java Integration in PHP
Using web services to pass data in between like SOAP
Using simple HTTP data passage between Java and PHP see (facejar uses the same technique)
Client site script (AJAX)
If you are after security, use option 1 otherwise I prefer using option 4 which is a bit faster when it comes to performance.
Everything I download seems hellbent on using all of Java EE. I need to build a single page to handle requests to it and do a tiny bit of processing based on parameters. This is to hook into another framework that will routinely call this URL.
I want a quick and easy way to create a page with some processing. Is there an easy way to do this using Java? I am using Java because I am comfortable with Java. I used SE for years and did some work in EE but I don't want all the stuff that comes with EE.
Should I maybe just avoid Java altogether and use something else. This needs to be deployed in a linux environment.
I used SE for years and did some work in EE but I don't want all the stuff that comes with EE.
Then just use a Servlet and that's all. Nothing, I repeat NOTHING, forces you to use "all that stuff" and your question is either a free rant or shows some deep misunderstanding.
You need Tomcat (or jetty, or any servlet container - jetty has an embeddable version btw)
You need a .jsp file and optionally an HttpServlet
Generally, it's not a good practice to put any processing code in a JSP, but if it is really simple and won't be extended, simply put the logic there - it is translated to a Servlet anyway.
yes, all the servlet based solutions are quite chubby.
jetty is all right, but the download is 20MB. that is ridiculous.
currently, the best choice is probably com.sun.net.httpserver which is bundled in JDK 6. you can easily implement your service.
It sounds like you could use PHP to do your processing. Call the page and POST the parameters to it, compute, and return the result.
If you are not very particular about using java and are willing to experiment, you should look at nodejs. It runs on V8 javascript engine and runs on linux.
There are a couple of fraemworks for nodejs for web apps:
Expressjs and spludo
as mentioned, you can do this very simply with jetty and a servlet, you don't even need a JSP if you just need a URL that does some processing based on request parameters and returns a response.
For development, it's really easy to create a dynamic web project in eclipse, just follow the steps in this article.
That said, I don't think java is a great choice for really lightweight stuff. PHP is probably the easiest thing to use if you just want to get it working yesterday.
You can use Java with FastCGI. This is very flexible, but also a bit low-level for most Java programmers.
If you aren't afraid of servlets (they are only a very small part of Java EE!), I can recommend JAX-RS, it is quite easy to get started with. If you client-side is JavaScript based, you can avoid using JSP (which I would recommend you to avoid).
For example, see backbone-jax-cellar. The Java source is here. For a Java app, this is light-weight. He is rolling his own DAO, but that's the price you pay for using Java and SQL and no dependencies (other than JDBC). The code is reminiscent of object-oriented PHP if you ask me. The point is, that if you have a JavaScript client, you don't need template rendering or all that cruft and a REST interface should be enough.
If you are afraid of the heavy build systems too, I made an example REST Todo app backend (which uses an existing frontend) that only requires a POSIX system, the JDK and sqlite3, and gets its own other dependencies (including webserver). I did not use a DAO. The repository front page has a README.
Another possibility is the Play Framework which does not use Java EE. It is rather heavy-weight, though. Full featured though. You would definitely need to use an IDE for this, you don't need that for developing JAX-RS/FastCGI apps.
I would reccomend Sinatra it is a very light-weight ruby web framework.