| Developer's Daily | Java Education |
| front page | java | perl | unix | DevDirectory |
Introduction to "Page Compilation"
The Java Web Server v1.1 introduced an exciting new technology called "Page Compilation". This technology makes it possible to generate dynamic HTML pages from hybrid HTML/Java source files by using a special servlet, named PageCompileServlet.
Why is this so exciting? In a nutshell, it makes it easier than ever before to bring dynamic Java servlet technology to your HTML pages. PageCompilation makes it easy to generate Java servlet pages while letting you keep using your favorite HTML authoring tools (Microsoft FrontPage, Netscape PageComposer, etc.).
We've found that the process of creating dynamic HTML pages with Java is now reduced to these simple steps:
Who's doing all the work around here?
The PageCompileServlet simplifies the process of creating Java servlets. The first time your hybrid HTML/Java file is requested, the PageCompileServlet does this work for you:
How about an example?
Let's walk through a quick and simple example so you can see this process in action. In following with tradition, we'll create a simple "Hello, world" JHTML page.
To start with, suppose you created an HTML file that looks like this with your favorite HTML-authoring tool:
If you're comfortable with HTML, that code isn't too exciting.
To make it interesting, let's add a little spice to it in the form of Page Compilation. Let's say you want to display the time and date within this exciting little page. Using Java Page Compilation, here's all you need to do:
Now, every time this page is accessed, the Java code will determine the current date and time from the web server, and display it in this Hello, World page. To make it easier to see, I've displayed the new Java code in a red color.
After creating this page, just save it in your Java Web Server 1.1 HTML directory structure, using a name like HelloWorld.jhtml. The first part of the name ("HelloWorld") isn't important, but you must save it with the '.jhtml' extension so it will be properly recognized by the PageCompileServlet.
After saving the file, just access it through your web browser. On my system, I saved the file in my public_html root directory, so I just entered this URL into my Netscape browser:
The first time the page is accessed
As you'll notice, the first time you access this page it will appear painfully slow, and you'll think something has gone wrong. Don't fret though, because this only happens when the page is accessed the first time. That's because the PageCompileServlet is doing a lot of work for you. The first time the page is accessed, your hybrid HTML/Java page is converted to servlet code and compiled automatically for you.
On all subsequent accesses, your HTML (or should I say "JHTML") page
returns very quickly.
If you ever change the page
If you ever change your JHTML page, it will again seem to be very slow
the first time you access it after your change. Again, that's because the
PageCompileServlet is doing the dirty work for you. The same process occurs,
and all subsequent accesses will be very fast.
Imagine ...
Using your imagination, you can see why this process is so good:
Summary
Well, that's a quick introduction into the Page Compilation process. If you have access to the Java Web Server, or another server that supports Page Compilation, I recommend giving it a try to see if it can make your life easier and more productive. Sun has certainly made the process of generating dynamic content very painless and simple.
In the future we're going to go way beyond the process of demonstrating
this simple "Hello, world" page. We'll throw in some database access
technology, networking, and whatever else we can think of that might be
valuable and interesting. In the meantime, if you have any ideas for Page
Compilation topics you'd like to see us cover, just
write our Java team with your ideas. We'll be glad to incorporate your
ideas into our future articles.
Relevant version information:
| Server: | Sun Java Web Server 1.1 |
| JDK: | JDK 1.1.x |
| Article publication date: | December 18, 1998 |
Copyright 1998-2008 DevDaily Interactive, Inc.
All Rights Reserved.