Client-Side Presentation Logic
629
%>
<%
String myStr = myFinder.locateDealsXML(0);
int chop = myStr.indexOf(">");
myStr = myStr.substring(chop + 1);
%>
<%= myStr %>
This JSP uses the DealsFinder class from the VacationServlet to display all the available sell-offs
in XML format. Two things to note, that are very important when using JSP to generate XML output for
direct consumption by browsers, are:
1. Make sure you use the contentType attribute of the page directive to specify the MIME
type text/xml
2. Make sure that <?xml version="1.0" ?> is the very first line in the file with no leading
blank space whatsoever.
Failing to ensure that either one of the above is taken care of will render your work very difficult to
debug, especially when working with multiple browser versions.
The XSLT stylesheet, tripdeals.xsl, contains:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" version="1.0">
<xsl:template match="/">
<HTML>
<BODY>
<TABLE WIDTH="600">
<TR><TD><H1>Wrox Vacations Center</H1></TD></TR>
<TR><TD><H2>Client-side XSLT Formatting - JSP Generated XML
Data</H2></TD></TR>
</TABLE>
<TABLE BORDER="1">
<TR>
<TD><b>Trip Number</b></TD>
<TD><b>Region</b></TD>
<TD><b>Location</b></TD>
<TD><b>Start</b></TD>
<TD><b>Duration</b></TD>
<TD><b>Price</b></TD>
</TR>
<xsl:for-each select="sell-off/trip">
<TR>
<TD><xsl:value-of select="@number"/></TD>
<TD><xsl:value-of select="@region"/></TD>
<TD><xsl:value-of select="location"/></TD>
<TD><xsl:value-of select="startdate"/></TD>
<TD><xsl:value-of select="duration"/></TD>
<TD><xsl:value-of select="price"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>