Putting It Together


The JSP in Listing B.1 shows some of the XML tags we have discussed, and Figure B.1 shows the corresponding output.

click to expand
Figure B.1: The outout from the JSTL example

Listing B.1: An example JSP using JSTL XML tags

start example
 <%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %> <!—other JSP code—> <x:parse var="catalog" scope="application">     <items>         <item>             <quantity>3</quantity>             <productnumber>229AXH</productnumber>                 <description>High speed photocopier machine with automatic sensors                                                                     </description>             <unitcost>1939.99</unitcost>         </item>         <item>             <quantity>1</quantity>             <productnumber>1632</productnumber>             <description>One box of color toner cartridges</description>             <unitcost>43.95</unitcost>         </item>     </items> </x:parse> <b> forEach example </b> c Here is the value stored in the "parseditems" variable <x:forEach var="item" select="$applicationScope:catalog/items/*"> <br>     Item quantity: <x:out select="$item/quantity"/> <br>     Item product number: <x:out select="$item/productnumber"/> <br>     Item product number: <x:out select="$item/productdescription"/> <br>     Item cost:$  <x:out select="$item/unitcost"/> <br><br> </x:forEach> <hr> <b> if example </b> <br> <x:forEach var ="item" select="$applicationScope:catalog/items/*">      <x: if<D>  select="$item/unitcost >1000">      This item has a cost greater than $1000: <x:out select="$item/description"/>      </x:if> </x:forEach> <hr> <b> choose-when example </b><br> <x:forEach var="item" select="$applicationScope:catalog/items/*"> <x:choose>      <x:when  select="$item/unitcost >1000">          This item has a cost greater than $1000: $ <x:out select="$item/unitcost"/>          <br>  <x:out select="$item/description"/>      </x:when>      <x:when   select="$item/unitcost < 100">           This item has a cost less than $100: $ <x:out select="$item/unitcost"/>           <br> <x:out select="$item/description"/>      </x:when> </x:choose> </x:forEach> <hr> <b> otherwise example </b> <br> <x:forEach var="item" select="$applicationScope:catalog/items/*"> <x:choose>      <x:when   select="$item/unitcost < 10">           This item has a cost less than $10: $ <x:out select="$item/unitcost"/>          <br> <x:out select="$item/description"/>      </x:when>      <x:otherwise>         This item is more than $10 <x:out select="$item/description"/>         <br>      </x:otherwise> </x:choose> </x:forEach> 
end example




Java Web Services Architecture
Java Web Services Architecture (The Morgan Kaufmann Series in Data Management Systems)
ISBN: 1558609008
EAN: 2147483647
Year: 2005
Pages: 210

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net