Difference between PHP and JSP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi All,
        can anybody tell me detailed diffrence between PHP and JSP?

Re: Difference between PHP and JSP

Quoted text here. Click to load it

Wow. :-)

Can you tell me the detailed differences between Chinese and English?

The language of JSP is Java and based on the J2EE specifications.
The language in PHP is PHP.

Both languages have their pro's and con's, but to ask us to describe the  
detailed differences: that is a lot to ask. :-)

Some differences might include:
java: strongtyped data. All variables should be declared.
PHP: flexible, variable behave 'naturally' alltough they all have a type  
defined behind the scenes (like integer, string, etc)

Java: Objectoriented, always.
PHP: You can mix in Objectoriented stuff to your liking.

JSP: Really resident and running on a server, so you always have some  
running processes you can use for timers, etc.
PHP: Will fire up the php-engine when a request arives from a client.
So if you need sheduled tasks, you have to fall back to cron and the like.

And for starters:
Java is surely harder to master compared to PHP, but more suitable for  
complex tasks.

Erwin Moller

Re: Difference between PHP and JSP

Thanx Erwin


Re: Difference between PHP and JSP

 >>Shailesh<< wrote:
Quoted text here. Click to load it
Hi Shan,

If i am right there is one difference between php and JSP that really  
matters fot how you can build user interfaces: with php the first file  
(called the script, the one that is executed by php in reaction to a  
http request) is much like a JSP. But if you include another file, it  
also acts like a JSP, kind of 'inserting' its output on the place you  
called it from.

For example if myScript.php contains:

    <TITLE>My Page</TITLE>
    <?php include('myBody.inc.php') ?>

this will output the content coming from file 'myBody.inc.php' on the  
location of <?php include('myBody.inc.php') ?>. Now i guess you can do  
this kind of thing too with JSP. But there is an important difference:
the code from the included file is executed inside the function it is  
included from. In the example there is no function, but in the following  
example there is:

in 'myScript.php':

    $page = new MyPage();

in 'MyPage.class.php':


class MyPage {

     function service() {

     function printTitle() {
    print "My Page";

     function printBodyPart() {
    $part = new MyBodyPart();

in 'MyPage.skin.php':

    <TITLE><? $this->printTitle() ?></TITLE>
     <?php $this->printBodyPart() ?>

in 'MyBodyPart.class.php':

class MyBodyPart {

     function service() {

     function printMessage() {
    print "Hello World";

in 'MyBodyPart.skin.php':

<B><?php $this->printMessage() ?></B>

Becuase the skin files are included inside methods, the $this variable  
will reference the object whose method includes the skin. This way we get:
- separation of layout and OOP code,
- pages composed from reusable parts
And all this without a framework, without a template engine, all you  
need is to follow a simple pattern! I guess this would not be as simple  
with JSP. (Please give us the same example in JSP it i am wrong)


Henk Verhoeven,

Site Timeline