WebRef Update: Featured Article: Building Dynamic Pages with XML, XSL and JSP | 2
Building Dynamic Pages with XML, XSL and JSP
The directives in the "header" tell the JSP engine about the page and give it the opportunity to import supporting class libraries (such as the JDBC classes). One important directive is 'contentType="text/xml"' which tells the server to send the appropriate MIME type to the browser so it knows to expect XML content.
JSP pages have access to the same information as CGI scripts. If a GET or POST query has been made, the JSP (or servlet) can retrieve the data by means of a "request" statement. The page can first check to see if there are any variables to process. If not, it sends out the HTML page with three query forms. For this section, it is important that the appropriate "<!DOCTYPE..." is sent before any other data in order for the HTML to be rendered by the browser. The target of the form submissions is the JSPpage.
Once a form is submitted, the third section, containing JSP code, is executed. As with the other two sections, a special XSL stylesheet tag must appear before all content. This tag references the "areacode.xsl" stylesheet that is used by the browser to produce the final page results. The JSP code connects to the database then selects the appropriate data and outputs an XML stream of area code records.
XSL stylesheets use a template matching system to find and then process XML content. All processing starts at the root document element and proceeds from there. areacode.xsl matches each area code record and puts the content into a table row. Further processing (such as sorting or hiding) can be done with XSL if necessary.
A simple, yet useful application has been built with just two files and some information stored in a database. More extensive applications can be built with Java Server Pages that take advantage of built-in session capabilities and that work in conjunction with Java Servlets. Furthermore, we have only scratched the surface of the power of XML and XSL. These three open technologies will become essential components in your toolbox as you endeavor to build more dynamic and personalzied sites.
Source Code & Data Files for this article
Java Server Pages Reference
W3C XML Site
W3C XSL Site
MySQL Database Home
MySQL JDBC Driver
Jakarta/Tomcat Project Home
DocBook XSL Markup Library
About the Author:
Bob's been an Internet inhabitant for thirteen years (since "back in the days when folks still knew how to spell UUCP") and has been involved in various large-scale Web site development projects including www.biblestudytools.net. At present, Bob is an e-Business Technology Development Sr. Consultant at Johnson & Johnson, as well as being an adjunct professor in the Computer Science deptartment of Moravian College in Bethlehem, PA.
You can contact Bob at email@example.com.
Previous: The Challenge and Standards
Revised: May 9, 2000