Java Servlets vs. PHP

Status
Not open for further replies.

jmmv

Ars Scholae Palatinae
970
Hi all

I know PHP, and I have done several pages using it. Although I find it a bit confusing when trying to maintain the webpages, all html and php mixed; it's not fun.

I have also listened recently about the Java Servlets and JSP pages. So I went and installed Jakarta Tomcat, then tried the JSP examples. I find them cool, and they seem a good idea to maintain projects that depend heavily on a "logical" system. Though, I'm not used to JSP (yet) and I can't give my oppinion.

Which are the real advantadges (if any) of using JSP against PHP? Differences?

Thanks!
 
Use templates.

I know this doesnt directly respond to your question, but if you're using php its time to learn about templates.

http://phpbuilder.com/columns/sascha19990316.php3

That provides a pretty simple introduction.

For php there are tons of libraries available ... XTemplate, QuickTemplate, FastTemplate, etc etc. I would love to find something like the above that work with java servlets ( i know...not too hard to create one )


futang

ps Maybe i should have said that the template system used in the above libraries succeeds in completely sepearting php and html, use it, love it.
 

MikeApp

Ars Centurion
257
Subscriptor
My experience with PHP is limited, but the big wins for JSP/Servlets (for me) are:

(1) Objects. I much prefer OO coding, especially when I have to keep session information. It's much easier to keep track of a single object that encapsulates data ( e.g., the user's access privileges ). Beans help you keep your sanity in a larger application.
(2) Tag libraries. You can write custom tags that are somewhat like servlets. This lets you keep Java code out of your .jsp files. They are part of the standard, not an add-on.
 

philmes

Ars Tribunus Angusticlavius
9,963
I like them both, but for different things. I tend to use PHP to build a prototype or for just throwing something together and Java for more substantial projects. One of the things that bugs me about PHP is it's poor OO support - this may not be a problem for you, but I like my interfaces and abstract classes. The lack of a standardised DB API is also a nusiance although things like PEAR make this less of a problem than it used to be.

When I build a Java web app, I typically use a mixture of Servlets and JSP custom tags - I very rarely embed JSP code directly into the page. I'll usually build a servlet which generates XML before running it through an XSLT transform to generate appropriate output.
 

jmmv

Ars Scholae Palatinae
970
:eek: I'm starting to like the idea of using servlets. I have tried to do some pages with session management and PHP... it is a big mess.

I really like OOP so working with Java servlets may be my best bet hehehe. And as you say, using a class for user management and control will be great!

About database access, you are right. It is annoying to get a simple page working with mysql and postgresql, for example. I guess that with servlets and beans I'll be able to use JDBC to access them homogeneusly, right?

There are several terms that you have said, Philmes, that I do not understand... I'm going to start RTFM ;) But... about XML... the servlet produces a XML output, right. And then what, you use XSLT (dunno what's it) to convert XML to HTML or what?

Thanks!
 

cyb0rg

Ars Scholae Palatinae
652
Ive used PHP to develop a few e-commerce sites and I am currently using it to develop an enterprise-level application for a Management Service Provider (think Application Service Provider). In general I find PHP great for rapid application development but, for biger projects I find it lacking, especially with OO work. PHP also doesnt support function overloading which is a big pisser to me always. I havent tried JSP yet but I have been thinking about looking into it.
 

Thank You and Best of Luck!

Ars Legatus Legionis
21,219
Subscriptor
Originally posted by jmmv:

About database access, you are right. It is annoying to get a simple page working with mysql and postgresql, for example. I guess that with servlets and beans I'll be able to use JDBC to access them homogeneusly, right?

Well that's technically the promise of JDBC, that it will allow your applications to be data source independant. It's not really completely that way, but it can almost be so long as you are careful not to use any specific features of one DBMS that aren't available in others. If you really want to have a good framework for data source independant applications you should try WebObjects, but it's not free, and might be a bit more to bite off than you intended to.

-Nathan
 

Thank You and Best of Luck!

Ars Legatus Legionis
21,219
Subscriptor
Between using PHP and JSP, I'd have to give the nod to JSP. Using JSP gives you direct access to the huge class libraries available with the java distribution. You get ready access to load balancing classes as well as a CORBA implementation. I'd agree that PHP works well for generally small scale applications which don't require a lot of standards compliant security and interoperability, but JSP can take you up to that extra notch relatively easily. It just depends on what you need to do.

-Nathan
 

pelican

Wise, Aged Ars Veteran
184
Hmmm... it really depends on the application you're developing for.

PHP is probably easier to develop for the newer to programming crowd in because of its simple straight forward (not requiring O-O) nature, but it's really easy to end up writing really ugly hacks in PHP if you're mixing HTML, escaping in and out all the time, and doing weird stuff in general. You just have to be careful about not making your code completely unintelligable with all kinds of crazy shit going on (guilty as charged, I am.)

For slightly better speed of execution and more object-oriented features, use JSP. But if you're new to programming, it will take longer to learn than PHP (IMHO.) Java is also an imminently more stylish technology than PHP is, and people give extra style points to Java developers. PHP is about as stylish as WalMart plastic plants in a lot of IT departments, but this reputation is probably not deserved.

As for the messy PHP-HTML code thing, I've gotten pretty good at abstracting HTML from PHP, using homemade objects and functions, and a couple of things from Sourceforge as well (PHPLIB is an excellent thing to pick up.) Distros of PHP also come with some pretty slick base classes for HTML products - PEAR. Check out http://pear.php.net or a php manual for more info on these.

Basically, JSP has some advantages, and PHP does as well. I prefer PHP because I prefer C, and it probably is just personal preference in the end.

--pelican
 

jmmv

Ars Scholae Palatinae
970
pelican, does JSP perform better than PHP?

About what I have done with PHP... I find it ok to do some simple things in web pages, for example simple SQL queries. But for session management, I'm getting more convinced that JSP is the winner :)

BTW, I'm not new to programmer. I really like C++, and have done several things. OTOH, I do not remember much about Java hehe so I need to retake docs and reread them carefully. I think I'll get it in a few days, at least for basic things.
 
Status
Not open for further replies.