The JSP Files (part 1): Purple Pigs In A Fruitbasket - Studying The Foundations (
Page 2 of 7 )
JSP is based on
a multi-tier architecture, which can best be explained by comparing it to the
architecture seen on non-JSP sites (read: PHP- or ASP-driven sites). In the
typical Apache/PHP/mySQL architecture, you have a Web server and a database
server at one level, with a scripting language like PHP taking care of the
communication between the two to churn out dynamic content. While this kind of
architecture is fine for sites that attract a middling amount of traffic, it
begins to display its warts when traffic increases and the load on the database
and Web servers goes up.
The JSP architecture, on the other hand,
involves more than one level, immediately making it more scalable and
maintainable.
In case you're wondering what the long words mean, scalable
implies that you can easily increase, or "scale up", your systems as traffic
increases, while maintainable implies that it is possible to simply modify one
part of the system - changing over from one database to another, for example -
without affecting other areas.
In the context of JSP, a multi-tier
architecture involves the Web server for static HTML content, the application
server for JavaBeans and servlets, and the database server for database
connectivity. Additionally, you can combine JSP with JavaBeans and Java servlets
to create complex Web applications which build upon previously-released and
tested code modules, thereby simplifying code maintenance and increasing
reusability.
It is important to note here that JSP code is not read
line-by-line, as with PHP; it is first converted into a servlet (a bytecode
version of the program) and then invoked by a servlet engine (such as Tomcat) to
perform the required actions. Once the servlet is executed, the results are sent
back to the client. Since the servlet engine has to compile the servlet the
first time around, displaying a JSP page can take a little while the first time
you access it; however, the next time around, response time will be dramatically
reduced, since the servlet will have already been compiled and therefore ready
for immediate use.