⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jstl7.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;${bookRow[7]}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;c:if test=&quot;${item.quantity &gt; inventory.quantity}&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;c:set var=&quot;sufficientInventory&quot; value=&quot;false&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h3&gt;&lt;font color=&quot;red&quot; size=&quot;+2&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fmt:message key=&quot;OrderError&quot;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;There is insufficient inventory for &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;i&gt;${bookRow[3]}&lt;/i&gt;.&lt;/font&gt;&lt;/h3&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/c:if&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/c:forEach&gt;&nbsp;&nbsp;&lt;/c:forEach&gt;&nbsp;&nbsp;&lt;c:if test=&quot;${sufficientInventory == &#39;true&#39;}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;c:forEach var=&quot;item&quot; items=&quot;${sessionScope.cart.items}&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;  &lt;c:set var=&quot;book&quot; value=&quot;${item.item}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;  &lt;c:set var=&quot;bookId&quot; value=&quot;${book.bookId}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;sql:query var=&quot;books&quot; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql=&quot;select * from PUBLIC.books where id = ?&quot; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;sql:param value=&quot;${bookId}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/sql:query&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;c:forEach var=&quot;bookRow&quot; begin=&quot;0&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;items=&quot;${books.rows}&quot;&gt;&nbsp;&nbsp;          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;sql:update var=&quot;books&quot; sql=&quot;update PUBLIC.books set&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inventory = inventory - ? where id = ?&quot; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;sql:param value=&quot;${item.quantity}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;sql:param value=&quot;${bookId}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/sql:update&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/c:forEach&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/c:forEach&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h3&gt;&lt;fmt:message key=&quot;ThankYou&quot;/&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${param.cardname}.&lt;/h3&gt;&lt;br&gt;  &nbsp;&nbsp;&lt;/c:if&gt;&lt;/sql:transaction&gt;<a name="wp84910"> </a></pre></div><a name="wp77082"> </a><h3 class="pHeading2">query Tag Result Interface</h3><a name="wp75351"> </a><p class="pBody">The <code class="cCode">Result</code> interface is used to retrieve information from objects returned from a <code class="cCode">query</code> tag. </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">public interface Result&nbsp;&nbsp;public String[] getColumnNames();&nbsp;&nbsp;public int getRowCount()&nbsp;&nbsp;public Map[] getRows();&nbsp;&nbsp;public Object[][] getRowsByIndex();&nbsp;&nbsp;public boolean isLimitedByMaxRows();<a name="wp76211"> </a></pre></div><a name="wp75325"> </a><p class="pBody">For complete information about this interface, see the API documentation for the <code class="cCode"><a  href="http://java.sun.com/j2ee/1.4/docs/api/index.htmlapi/javax/servlet/jsp/jstl/sql/package-summary.html" target="_blank">javax.servlet.jsp.jstl.sql</a></code> package.</p><a name="wp75363"> </a><p class="pBody">The <code class="cCode">var</code> attribute set by a <code class="cCode">query</code> tag is of type <code class="cCode">Result</code>. The <code class="cCode">getRows</code> method returns an array of maps that can be supplied to the <code class="cCode">items</code> attribute of a <code class="cCode">forEach</code> tag. The JSTL expression language converts the syntax <code class="cCode">${</code><code class="cVariable">result</code><code class="cCode">.rows}</code> to a call to <code class="cVariable">result</code><code class="cCode">.getRows</code>. The expression <code class="cCode">${books.rows}</code> in the following example returns an array of maps.</p><a name="wp70265"> </a><p class="pBody">When you provide a array of maps to the <code class="cCode">forEach</code> tag, the <code class="cCode">var</code> attribute set by the tag is of type <code class="cCode">Map</code>. To retrieve information from a row, use the <code class="cCode">get(&quot;</code><code class="cVariable">colname</code><code class="cCode">&quot;)</code> method to get a column value. The JSTL expression language converts the syntax <code class="cCode">${</code><code class="cVariable">map</code><code class="cCode">.</code><code class="cVariable">colname</code><code class="cCode">}</code> to a call to <code class="cVariable">map</code><code class="cCode">.get(&quot;</code><code class="cVariable">colname</code><code class="cCode">&quot;)</code>. For example, the expression <code class="cCode">${book.title}</code> returns the value of the title entry of a book map.</p><a name="wp70191"> </a><p class="pBody">The Duke's Bookstore page <code class="cCode"><a  href="../examples/web/bookstore4/web/bookdetails.txt" target="_blank">bookdetails.jsp</a></code> retrieves the column values from the <code class="cCode">book</code> map as follows.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;c:forEach var=&quot;book&quot; begin=&quot;0&quot; items=&quot;${books.rows}&quot;&gt;&nbsp;&nbsp;&lt;h2&gt;${book.title}&lt;/h2&gt;&nbsp;&nbsp;&amp;nbsp;&lt;fmt:message key=&quot;By&quot;/&gt; &lt;em&gt;${book.firstname}&nbsp;&nbsp;${book.surname}&lt;/em&gt;&amp;nbsp;&amp;nbsp;&nbsp;&nbsp;(${book.year})&lt;br&gt; &amp;nbsp; &lt;br&gt;&nbsp;&nbsp;&lt;h4&gt;&lt;fmt:message key=&quot;Critics&quot;/&gt;&lt;/h4&gt;&nbsp;&nbsp;&lt;blockquote&gt;${book.description}&lt;/blockquote&gt;&nbsp;&nbsp;&lt;h4&gt;&lt;fmt:message key=&quot;ItemPrice&quot;/&gt;: &nbsp;&nbsp;&lt;fmt:formatNumber value=&quot;${book.price}&quot; type=&quot;currency&quot;/&gt; &nbsp;&nbsp;&lt;/h4&gt;&lt;/c:forEach&gt;<a name="wp84884"> </a></pre></div><a name="wp68160"> </a><p class="pBody">The following excerpt from <code class="cCode"><a  href="../examples/web/bookstore4/web/bookcatalog.txt" target="_blank">bookcatalog.jsp</a></code> uses the <code class="cCode">Row</code> interface to retrieve values from the columns of a book row using scripting language expressions. First the book row that matches a request parameter (<code class="cCode">bid</code>) is retrieved from the database. Since the <code class="cCode">bid</code> and <code class="cCode">bookRow</code> objects are later used by tags that use scripting language expressions to set attribute values and a scriptlet that adds a book to the shopping cart, both objects are declared as scripting variables using the <code class="cCode">jsp:useBean</code> tag. The page creates a bean that describes the book and scripting language expressions are used to set the book properties from book row column values. Finally the book is added to the shopping cart.</p><a name="wp69951"> </a><p class="pBody">You might want to compare this version of <code class="cCode">bookcatalog.jsp</code> to the versions in <a  href="JSPIntro.html#wp69778">JavaServer Pages Technology</a> and <a  href="JSPTags.html#wp74644">Custom Tags in JSP Pages</a> that use a book database JavaBeans component. </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;sql:query var=&quot;books&quot; &nbsp;&nbsp;dataSource=&quot;${applicationScope.bookDS}&quot;&gt;&nbsp;&nbsp;select * from PUBLIC.books where id = ?&nbsp;&nbsp;&lt;sql:param value=&quot;${bid}&quot; /&gt;&lt;/sql:query&gt;&lt;c:forEach var=&quot;bookRow&quot; begin=&quot;0&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;items=&quot;${books.rowsByIndex}&quot;&gt; &nbsp;&nbsp;&lt;jsp:useBean id=&quot;bid&quot;  type=&quot;java.lang.String&quot; /&gt;&nbsp;&nbsp;&lt;jsp:useBean id=&quot;bookRow&quot; type=&quot;java.lang.Object[]&quot; /&gt;&nbsp;&nbsp;&lt;jsp:useBean id=&quot;addedBook&quot; class=&quot;database.BookDetails&quot;&nbsp;&nbsp;&nbsp;&nbsp;scope=&quot;page&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;addedBook&quot; property=&quot;bookId&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;${bookRow[0]}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;addedBook&quot; property=&quot;surname&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;${bookRow[1]}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;addedBook&quot; property=&quot;firstName&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;${bookRow[2]}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;addedBook&quot; property=&quot;title&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;${bookRow[3]}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;addedBook&quot; property=&quot;price&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;${bookRow[4])}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;addedBook&quot; property=&quot;year&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;${bookRow[6]}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;addedBook&quot; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property=&quot;description&quot; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;${bookRow[7]}&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;addedBook&quot; property=&quot;inventory&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value=&quot;${bookRow[8]}&quot; /&gt;&nbsp;&nbsp;&lt;/jsp:useBean&gt;&nbsp;&nbsp;&lt;% cart.add(bid, addedBook); %&gt;&nbsp;&nbsp;...&lt;/c:forEach&gt;<a name="wp84759"> </a></pre></div>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="JSTL6.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="JSTL8.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -