XML technologies / XSLT / Java and XSLT / Introduction / Beyond dynamic websites
(Excerpt from “Java und XSLT” by Eric M. Burke)
You probably know something about servlets: server-side Java classes offering a fast, portable alternative to CGI scripts. They excel at retrieving database data and producing XHTML for browsers. They also handle HTTP POST and GET requests, for example for online book orders. More powerful technologies are needed for true web applications rather than simple websites.
Web development challenges
Web applications can be harder to develop than graphical Swing or AWT applications. Most difficulties fall into these categories:
Hypertext Transfer Protocol (HTTP)
HTML limitations
Browser compatibility
Concurrency
HTTP is a simple client-server protocol. Browsers normally use it to communicate with web servers, though other protocols include HTTPS for encryption and FTP for downloads. HTTP uses request-response exchanges initiated by the browser. Clicking a link makes a new request; the server processes it and sends a response, ending that exchange.
This cycle is understandable but makes it hard to maintain state information while users navigate a complex application. For a shopping cart, a servlet stores data while waiting for another request. It must then associate the cart with the right client among hundreds or thousands. Without a timeout it cannot detect an abandoned cart, for example when the user visits a competitor. HTTP prevents the server from initiating conversation, so it cannot periodically ping clients as a conventional client-server application might.
HTML is another obstacle: it was not designed to rival rich GUI toolkits, yet customers increasingly demand web applications. Its small set of primitive GUI components makes this challenging. Advanced HTML is beyond this book, but XSLT can separate HTML generation from business logic and servlet code. As HTML grows more complex, this separation becomes more valuable.
Popular browsers are not fully compatible, so applications require testing on many platforms. XSLT helps with reusable stylesheets for common HTML and imported or included browser-specific fragments. XML data and business logic remain the same for all browsers even with multiple stylesheets.
Finally, a servlet must handle concurrent requests. Explicit synchronization often reduces performance by queuing requests. Concurrent processing will be central to the XSLT servlet design in later chapters.
Web applications
The distinction between website and web application is subjective. Applications generally offer richer interaction and are harder to build. Sites mostly display information with occasional submission forms, for which HTML and simple CGI suffice. Applications fulfill specific business or technical functions, often replacing existing systems with browser access. Developers must reproduce existing functionality in HTML despite its limited GUI capabilities. Most application screens are dynamic and personalized, while most website pages are static.
Java, XML and XSLT suit modular applications. One programmer can develop backend data access while a designer creates the HTML interface, a servlet expert builds the web layer and another person defines XML. Programmers and designers usually define stylesheets together, though a lack of interactive tools makes this more of a programming task.
XML also integrates business systems and databases. Adding an XML layer to data access lets the web layer retrieve XML regardless of operating system or hardware. XSLT converts it to HTML with little custom code, saving development work.
Non-browser clients
Applications may need to communicate with software rather than browsers. Rich Swing clients often serve internal users while remote staff use XHTML browsers. XML suits both: raw XML goes to Swing and XSLT generates XHTML views of the same data.
XSLT can also convert XML into another XML form. For example, a client may expect:
<name>Eric Burke</name>But the web data looks like this:
<vorname>Eric</vorname><nachname>Burke</nachname>XSLT can convert these data to the simpler form expected by the client.
SOAP
Raw XML works with any operating system, hardware or language. Existing Visual Basic clients can remain unchanged while a portable Java solution exposes business data remotely. Custom XML formats, however, require writing message encoding and decoding code for clients and applications.
The Simple Object Access Protocol (SOAP) standardizes XML message exchange. Microsoft introduced SOAP, then submitted it to W3C, and many companies adopted it. Its simple structure lets vendors quickly develop tools for exchanges between applications and any client.
Since SOAP messages are XML, stylesheets can create and modify them. Retrieve XML from a relational database, transform it into SOAP and deliver it to a client written in any language. For standardization status, see SOAP Specifications.
Wireless applications
Phones, PDAs and other mobile devices seem poised for major growth. Their web business model and future technologies remain uncertain. WAP (Wireless Application Protocol) is currently popular and uses an XML language called WML (Wireless Markup Language) to render pages. Other proposals include CHTML (Compact HTML), but XHTML Basic looks most promising. Supported by W3C and based on XHTML modules, it appeared after WML and benefits from its concepts and experience.
With wireless development uncertain, XML and XSLT are the most common current approach. XML data supports different client markup and protocols without rewriting large portions of Java: new stylesheets support new devices. XSLT also serves traditional browsers and mobile clients with the same XML and Java business logic.
Copyright © 2002 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “Java und XSLT” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de