.php vs. .jsp

Status
Not open for further replies.
Trying not to be biased about PERL and Java, I'm trying to get a breakdown of these two conventions for developing web applications. I'm used to using .jsp cuz it's what we use at work, however a friend of mine said that .php is great, will run securly and stable on OpenBSD, and involves very minimal setup without having to install large Application Servers. Most importantly, it's what he runs and if I wanna host a web page on his sight, I should learn .php :p

So I guess I'm looking for some summary, point-for-point breakdown type stuff. This is so that I have a greater understanding of what I do at work, and also have an alternative means to build web pages in the future should I need one (as is the case). I'm sure there are plenty of experts out there seeing how www.arstechnica.com is developed with .php, so I'm sure it's a popular convention.

Links to resources would also be appreciated. Even the titles of some good books. Thanks all

Hero
 
I am a J2EE, PHP, Perl, .NET, ASP, JavaScript, PowerBuilder programmer so I have done a number of different styles of coding. If you come from a CGI,ASP background, learning PHP is really a short trip. With PHP you will generally put the majority of your business logic directly in the page. With JSP however, if you are writing PROPER JSP, you should have very little to no business logic in the actual JSP pages. JSP is designed to allow the developer to make a very strong break between business and presentation logic. With JSP, you should put your business logic in JavaBeans, Servlets, and/or EJB's, and the JSP page itself should be 80% HTML, and 20% actual JSP code basically calling on the external business logic elements to give you the pieces of data you need to stick into the HTML. (am I making sense or am I rambling?)

Anyway, from a "cost/speed/etc" standpoint, PHP, ASP, JSP are all very similar in speed and differences that can be noticed by an end user are negligible except in specific cicumstances. If you are looking flat out best response times, a comparison and a serious analysis of the project at hand needs to be done.

From a platform standpoint, it is easier to move JSP from one Application Server and/or operating system to another than it is to move PHP. There are some serious differences between PHP with CGI on IIS, PHP with ISAPI on IIS, PHP as CGI on Apache, and PHP with module on Apache. On the other hand, properly written JSP and associated Java code should be able to be moved easily from Jrun on Win32 to Tomcat on HPUX with no changes at all.


So now that I have given you the long answer, I'll give you the short answer. Should you learn PHP? Absolutely, you never know when you'll be working for someone and that knowledge of PHP will get you foot in the door on even better opportunities. PHP is a fun language with a lot of nifty features and is fairly easy to learn for any competent programmer. Just jump in and have fun.
 

martin007

Ars Tribunus Militum
2,783
Originally posted by Alton:
There are some serious differences between PHP with CGI on IIS, PHP with ISAPI on IIS, PHP as CGI on Apache, and PHP with module on Apache.
Alton, I'm interested in this point.

Do the differences affect the way one writes code? In other words, do the differences force you to rewrite code to move it from "platform" to platform?

I imagine these differences exist in only some features - which ones?

Thanks. :)
 
The majority of the differences I have run into, and i'm sure there are several I haven't, include system variables (like $DOCUMENT_ROOT) which exist on some platforms, and not on others, handling of Base64 encoding for submitting forms, and directory structure differences just to name a few.

Of course, if you are the person writing all the code, and you are careful, you can write all the code such that it is very portable between platforms. However, if someone else writes the code, it is a crap shoot. I talk about this from personal experiance with porting someone elses PHP website from Apache/Linux to W2K/IIS.

You asked if it affects the "way" you write code. Yes, it does. If you are the one writing the code, and you expect to be porting it, it is highly likely you will either avoid using many of the standard variables like $DOCUMENT_ROOT, or you will create alternate versions of those variables for use depending on the system being used.

From the standpoint of personal use for personal websites, the point is really moot. However, it requires much more consideration when you are talking about a production website that will contain 500-5000 files and several hundred thousand lines of code and a team of developers who will change over time.

[This message was edited by Alton on May 21, 2002 at 10:32.]
 

irish

Ars Tribunus Militum
1,557
Subscriptor++
I am a J2EE, PHP, Perl, .NET, ASP, JavaScript, PowerBuilder programmer so I have done a number of different styles of coding. If you come from a CGI,ASP background, learning PHP is really a short trip.

Even without that type of experience, PHP is a real easy language to catch onto :)

With PHP you will generally put the majority of your business logic directly in the page. With JSP however, if you are writing PROPER JSP, you should have very little to no business logic in the actual JSP pages.

That is one way, and is also most often the rookie way of creating PHP pages, as it is the method that is taught in every "beginning PHP" tutorial I have ever seen.

JSP is designed to allow the developer to make a very strong break between business and presentation logic. With JSP, you should put your business logic in JavaBeans, Servlets, and/or EJB's, and the JSP page itself should be 80% HTML, and 20% actual JSP code basically calling on the external business logic elements to give you the pieces of data you need to stick into the HTML. (am I making sense or am I rambling?)

In PHP, you can create class files that handle all the business logic, and simply inlucde those files in the display pages, and call their routines from the page. That way, you can have true separation of logic and display code, which I imagine will help immensely for the next person who needs to work on your code, as you basically said.

I myself fell into the procedural trap with my first big project, and I can't stop kicking myself, as I have the same code scattered over a couple hundred pages, where a more robust class file method would have made management so much easier.

Take a look at the sources for phpBB sometime, and you will see some nice examples of PHP written for portability.

Anyway, I have to say, learn PHP. JSP is great, but having both in your toolkit will be to your benefit.
 
Status
Not open for further replies.