The JSP Files (part 1): Purple Pigs In A Fruitbasket (
Page 1 of 7 )
Get to grips with Java Server Pages with this introductory
tutorial and find out how to use one of the more powerful server-side
languages around. This first part explains the history and basics of JSP
documents, and also illustrates variables, includes and the String object.Ever since Sun Microsystems (aka "the dot in dot-com") came up with Java, the
geeks have been screaming themselves hoarse about the wonders of this
technology. Terms like "platform-independent code" and "write once, run
anywhere" have been given so much airplay that even novice Java developers are
aware of them, and the language is also popular with talk-show pundits and
Internet consultants, who tout it as the solution to almost all problems of
cross-platform compatibility.
Now, we're big fans of Java - we've used it
in the past, and will do so again in the future - but this series of tutorials
isn't about Java. It's actually about an offshoot of Java, the innocuously-named
Java Server Pages, or JSP, which attempts to offer Web developers a compelling
alternative to traditional server-side scripting languages like Perl, PHP and
ASP.
How? First, a little history...
During the early days of the
Web, it was the sheer amount of (free!) content that encouraged people to use
it. Using the easy-to-learn HTML language, any one and their deaf grandma could
set up a Web page and reach out to other like-minded souls online. As the
infrastructure improved, content was no longer restricted to text; you could now
view pictures or watch videos on the Web. And as more and more people began
adding interactivity to their Web sites, a bunch of programming languages were
born in order to meet increasingly complex requirements.
The best-known
of these is, of course, Perl, although PHP and ASP are also popular favourites.
The problem with these languages, however, is that every request to the Web
server for a Web page generates a new process on the server, leading to
performance problems as visitor traffic increases.
Java offers a solution
to this problem, by using so-called "servlets" to create interactive Web sites
(a Java servlet is like a Java applet, except that it runs on the Web server,
not the client Web browser - and if you're confused now, wait till we get to
scriptlets). Java also makes it possible for brick-and-mortar companies to
interface their legacy systems with the new technologies available on the Web,
and rapidly develop and link back-office automation systems together via the
Internet.
However, servlets have a problem of their own - a simple
interface or logic modification could often result in far-reaching changes to
the servlet. And so, JSP was developed to separate application logic from the
interface, so that changes to one would not affect the other. Working closely
with developers like The Apache Group, JSP uses a tag-based approach (similar to
PHP and ASP) which allows designers to make changes to the user interface
without affecting application logic.
If you're wondering about
scalability, JSP supports component-based architectures using JavaBeans or
Enterprise JavaBeans; this allows a developer to create reusable code modules
and thereby speed up development time. And since this is Java, you can
seamlessly connect Web applications to legacy systems, thereby reducing the
costs of moving a real-world business into cyberspace. Say it with us - platform
independence rocks!