You are here: Re: Difference between PHP and JSP « PHP Programming Language « IT news, forums, messages
Re: Difference between PHP and JSP

Posted by Henk Verhoeven on 11/01/04 11:32

>>Shailesh<< wrote:
> Hi All,
> can anybody tell me detailed diffrence between PHP and JSP?
> Thanx
> Shailesh
>
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:

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

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':

<?php
require_once('MyPage.class.php');
$page = new MyPage();
$page->service();
?>

in 'MyPage.class.php':

<?php

class MyPage {

function service() {
include('MyPage.skin.php');
}

function printTitle() {
print "My Page";
}

function printBodyPart() {
require_once('MyBodyPart.class.php');
$part = new MyBodyPart();
$part->service();
}
}

in 'MyPage.skin.php':

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

in 'MyBodyPart.class.php':

class MyBodyPart {

function service() {
include('MyBodyPart.skin.php');
}

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)

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация