WebRef Update: Featured Article: Building Dynamic Pages with XML, XSL and JSP
Building Dynamic Pages with XML, XSL and JSP
Web sites used to be fairly predictable beasts. Mix some HTML with some CGI and you have a basic page that responds to the user. Today, if your site isn't dynamic, it's dead or at least on the endangered species list. While older tools, such as PHP, get the job done and proprietary beasts, like Microsoft's Active Server Pages (ASP), lock you into a platform, emerging tools and standards are available to help you streamline development and serve up fresh, dynamic content to your visitors.
This article walks you through the creation of a simple area code lookup form that uses a Java Server Pages (JSP) to retrieve data from a database, XML to hold the result of queries and XSL to put the finishing touches on the browser presentation.
JSPs are the open answer to ASPs. Simply stated, they are mixture of markup tags and Java code on the same page. You have the full power of Java and all it's class libraries to use in your development - including built-in database connectivity with the JDBC classes.
The Extensible Markup Language (XML) provides a structured way to represent information and can be used with the Extensible Stylesheet Language (XSL) to format and present a finished document for viewing. Internet Explorer 5.x is one of the best ways (as of this writing) to directly view XML/XSL documents, but you are able to run XML/XSL documents through other utilities to generate HTML (or XHTML output) for viewing by any browser.
The link to the full sources can be found at: www.cs.moravian.edu/~brudis/webreference/. This example application is based upon an area code database with three fields: area code, location (state), and description. From it, you can display the complete database, or lookup information on any one of the three fields - all with one JSP page.
If you do not have a Web server with inherent JSP capabilities, then I suggest going over to the Apache site and grabbing "Tomcat" - which is an open JSP/Servlet implementation under the Apache Software Foundation. IBM and Sun contribute to the project and it is a great starting point. Alternatively, you could use products like ServletExec and Jrun which provide similar functionality and can be added onto most modern Web servers and platforms.
To fully appreciate the power of the technology, you'll need to have the area code information stored in a database. If you don't have one handy, or dislike ODBC as much as I do, then grab a copy of MySQL and the JDBC driver for it. It's free, and easy to get setup and running.
Once you have a database and a JSP-engine, the application is a mere two files: areacode.jsp (which contains the form and lookup code) and areacode.xsl (which contains the presentation markup instructions). If you're running Tomcat, you can start the application by calling up a URL in IE: "http://www.some.svr:8080/areacode.jsp" provided you put the file in the "webpages" directory after the server build.
areacode.jsp is divided into three sections: the header, which contains the XML document tag and the JSP page directives; the HTML body, which is sent if there is no form input to process; and the JSP code that connects to the database and outputs XML tags.
Revised: May 9, 2000