








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
JSP pages execute as Java servlets, typically in the execution context of a Web server where they generate content-dependent response documents using data ...
Typology: Schemes and Mind Maps
1 / 14
This page cannot be seen from the preview
Don't miss anything!









XML (eXtensible Markup Language) is a set of syntax rules and guidelines for defining text-based markup languages. XML languages have a number of uses including:
guage objects to parse and transform XML messages and documents. In particu- lar, as part of the Java software environment, JSP pages can use objects that leverage the new Java APIs for processing XML data. Finally JSP technology provides an abstraction mechanism to encapsulate functionality for ease of use within a JSP page. This paper highlights how JSP pages can
Using XML Data Sources in JSP Pages
It is easy to use multiple data sources, including XML sources, in a JSP page; Figure 1 illustrates the standard way to do so. A page connects to a data source through a server-side object, transforms the information into data abstractions, and then renders the data using JSP elements.
JSP Page
XML
JDBC
Enterprise Bean
Bean
Custom Tag
In the following example, a JSP page retrieves XML data from two URLs and uses the data to generate an HTML page. Note that the URL can point to a source that dynamically generates XML data (See Generating XML From a JSP Page (page 9)) as well as a static XML document, and the same technique can be used to generate XML. The JSP page uses the parse custom tag to extract and store XML data in two objects: a customer and a collection of books. The page then extracts properties of the customer object and uses a custom tag to iterate through the collection and render a table that lists properties of the book objects.
<%@ taglib uri="..." prefix="tl" %>
** **
Welcome
Welcome
” >
One of the XML documents in this example (the book inventory data) is com- posed of XML fragments (book elements). It is not really necessary to parse the whole document into memory in order to extract the data—you can parse it, using SAX or JDOM, for example, and extract data from one fragment at a time. The following version of the example uses the iterateOnXMLStream custom tag to implement this alternative:
<%@ taglib uri="..." prefix="tl" %>
Welcome
as above ...
as above ...
Example 4 store.xsl
To apply the stylesheet, you programmatically invoke an XSLT processor from a JSP scriptlet or custom tag. The jakarta-taglibs project at the Apache Soft- ware Foundation hosts a tag library that contains a number of tags for processing XML input and applying XSLT transformations. The JSP page in Example 5 invokes the apply tag from this library with store.xsl to transform customer data and the book inventory.
<%@taglib uri="http://jakarta.apache.org/taglibs/xsl-1.0" prefix="xsltlib" %>
Book Inventory
Welcome ****!
On Sale Today ...
****The result of executing this JSP page appears below.
Generating Markup Languages Using JSP Pages
In order for Web-based services to have the broadest use it has become increas- ingly important that they be accessible from the widest variety of clients. Recent years have witnessed a proliferation of different types of user-oriented clients for Web-based applications: PDAs, WAP-enabled mobile phones, and landline voice clients. With the rise of business-to-business transactions, servers that consume XML can also be clients. The scenario we envision supporting looks like the fol- lowing:
Pages
Clients Data Sources
Web Layer
Custom Tags
Browser
Phone (wireless, landline))
Server
The main requirement for generating XML is that the JSP page set the content type of the page appropriately:
<%@ page contentType=”text/xml”%> ... XML document
With this change, the techniques described earlier to generate HTML content can be used to generate XML.
Generating Multiple Markup Languages There are several approaches to generating multiple markup languages from a Web application:
Single Pipeline In the single pipeline approach, the Web application’s JSP pages generate client- specific markup by applying transformations to incoming XML data. Each type of client requires a different stylesheet and the bulk of the development costs are associated with creating and maintaining these stylesheets.
Parse and Transform via Custom Tag
Clients Data Sources
Web Layer
JSP Page XML
XSL(HTML) XSL(WML) XSL(XML)
WML
HTML
XML
DHTML
XSL(DHTML)
This approach defers generation of both the static and dynamic portions of a response to runtime. The runtime costs are associated with:
If you are using XSLT transformations, you can improve the performance of transformations by creating a binary representation (using an XSLT compiler, for example, XSLTC) of a stylesheet. However, this also makes the maintenance process more complex: each time the presentation is changed, the stylesheet must be recompiled.
Sometimes the differences between clients are minor and may not merit a full- fledged transformation. For example, there are a number of slightly different browser-based desktop clients. In some cases, one may want to take full advan- tage of the differences instead of generating content for the minimum common denominator. Often the differences between these clients can be encapsulated into a custom tag that generates different content depending on the properties of the client.
Generating the presentation for clients with different interaction models and flow of control (for example, PC-based browsers versus WAP phones) will require very different transformations. For example, a mobile phone cannot display a table containing book inventory data. Instead the data would have to be dis- played as a set of nested lists. Supporting such transformations increases both the development and runtime costs.
The following table summarizes the costs of each approach:
Combination You can combine the single and multiple pipeline approaches. If your clients speak different languages you probably should use one pipeline for each lan- guage. To generate dialects of a language, you can apply XSLT transformations to that language’s pipeline.
Conclusion
JavaServer Pages technology and XML are natural partners for developing Web applications that use heterogeneous data sources and support multilingual cli- ents. This paper has described several approaches to addressing these require-
Single Client-specific stylesheets
Parse XML data Parse stylesheet Apply transformation
Multiple Data abstractionsClient-specific JSP pages
Parse XML data Instantiate and initialize data abstraction components Execute JSP page
JSP Page
Clients Data Sources
Web Layer
Bean
Custom Tag
WML
HTML
XML (^) JSP Page
JSP Page
XML WML
XSLT
L^ a b
DHTML
ments that trade off development and maintenance versus runtime costs. As part of the general-purpose Java software platform, JSP technology provides devel- opers with the capability to evaluate these trade-offs and to adopt an architecture for XML processing that best satisfies their particular application requirements.
Resources
For further information about the technologies described in this paper, see the following resources: