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

📄 jstl4.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  <head>    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />    <meta http-equiv="Content-Style-Type" content="text/css" />    <title>Core Tags</title>    <link rel="StyleSheet" href="document.css" type="text/css" media="all" />    <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" />    <link rel="Table of Contents" href="J2EETutorialTOC.html" />    <link rel="Previous" href="JSTL3.html" />    <link rel="Next" href="JSTL5.html" />    <link rel="Index" href="J2EETutorialIX.html" />  </head>  <body>    <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="JSTL3.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="JSTL5.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">    <blockquote><a name="wp86154"> </a><h2 class="pHeading1">Core Tags</h2><a name="wp86155"> </a><p class="pBody"><a  href="JSTL4.html#wp86162">Table 14-3</a> summarizes the core tags, which include those related to expressions, flow control, and a generic way to access URL-based resources whose content can then be included or processed within the JSP page.</p><div align="left"><table border="1" summary="Core Tags" id="wp86162">  <caption><a name="wp86162"> </a><div class="pTableTitle">Table 14-3   Core Tags&nbsp;</div></caption>  <tr align="center">    <th><a name="wp86170"> </a><div class="pCellHeading">Area</div></th>    <th><a name="wp86172"> </a><div class="pCellHeading">Function</div></th>    <th><a name="wp86174"> </a><div class="pCellHeading">Tags</div></th>    <th><a name="wp86176"> </a><div class="pCellHeading">Prefix</div></th></tr>  <tr align="left">    <td colspan="1" rowspan="4"><a name="wp86178"> </a><div class="pCellHeading">Core</div></td>    <td><a name="wp86180"> </a><div class="pCellBody">Variable Support</div></td>    <td><a name="wp86182"> </a><div class="pCellBody"><code class="cCode">remove</code></div><a name="wp86183"> </a><div class="pCellBody"><code class="cCode">set</code></div></td>    <td colspan="1" rowspan="4"><a name="wp86185"> </a><div class="pCellBody"><code class="cCode">c</code></div></td></tr>  <tr align="left">    <td><a name="wp86189"> </a><div class="pCellBody">Flow Control</div></td>    <td><a name="wp86191"> </a><div class="pCellBody"><code class="cCode">choose</code></div><a name="wp86192"> </a><div class="pCellBody"><code class="cCode">&nbsp;&nbsp;when</code></div><a name="wp86193"> </a><div class="pCellBody"><code class="cCode">&nbsp;&nbsp;otherwise</code></div><a name="wp86194"> </a><div class="pCellBody"><code class="cCode">forEach</code></div><a name="wp86195"> </a><div class="pCellBody"><code class="cCode">forTokens</code></div><a name="wp86196"> </a><div class="pCellBody"><code class="cCode">if</code></div></td></tr>  <tr align="left">    <td><a name="wp86202"> </a><div class="pCellBody">URL Management</div></td>    <td><a name="wp86204"> </a><div class="pCellBody"><code class="cCode">import</code></div><a name="wp86205"> </a><div class="pCellBody"><code class="cCode">&nbsp;&nbsp;param</code></div><a name="wp86206"> </a><div class="pCellBody"><code class="cCode">redirect</code></div><a name="wp86207"> </a><div class="pCellBody"><code class="cCode">&nbsp;&nbsp;param</code></div><a name="wp86208"> </a><div class="pCellBody"><code class="cCode">url</code></div><a name="wp86209"> </a><div class="pCellBody"><code class="cCode">&nbsp;&nbsp;param</code></div></td></tr>  <tr align="left">    <td><a name="wp86215"> </a><div class="pCellBody">Miscellaneous</div></td>    <td><a name="wp86217"> </a><div class="pCellBody"><code class="cCode">catch</code></div><a name="wp86218"> </a><div class="pCellBody"><code class="cCode">out</code></div></td></tr></table></div><p class="pBody"></p><a name="wp63882"> </a><h3 class="pHeading2">Variable Support Tags</h3><a name="wp72886"> </a><p class="pBody">The <code class="cCode">set</code> tag sets the value of an EL variable or the property of an EL variable in any of the JSP scopes (page, request, session, application). If the variable does not already exist, it is created. </p><a name="wp65014"> </a><p class="pBody">The JSP EL variable or property can be set either from attribute value: </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;c:set var=&quot;foo&quot; scope=&quot;session&quot; value=&quot;...&quot;/&gt; <a name="wp65016"> </a></pre></div><a name="wp65018"> </a><p class="pBody">or from the body of the tag: </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;c:set var=&quot;foo&quot;&gt; &nbsp;&nbsp;... &lt;/c:set&gt;<a name="wp65020"> </a></pre></div><a name="wp81215"> </a><p class="pBody">For example, the following sets a EL variable named <code class="cCode">bookID</code> with the value of the request parameter named <code class="cCode">Remove</code>:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;c:set var=&quot;bookId&quot; value=&quot;${param.Remove}&quot;/&gt;<a name="wp81216"> </a></pre></div><a name="wp73979"> </a><p class="pBody">To remove an EL variable, you use the <code class="cCode">remove</code> tag. When the bookstore JSP page <code class="cCode"><a  href="../examples/web/bookstore4/web/bookreceipt.txt" target="_blank">bookreceipt.jsp</a></code> is invoked, the shopping session is finished, so the <code class="cCode">cart</code> session attribute is removed as follows:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;c:remove var=&quot;cart&quot; scope=&quot;session&quot;/&gt;<a name="wp81116"> </a></pre></div><a name="wp74001"> </a><h3 class="pHeading2">Flow Control Tags</h3><a name="wp73998"> </a><p class="pBody">To execute flow control logic, a page author must generally resort to using scriptlets. For example, the following scriptlet is used to iterate through a shopping cart:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;% &nbsp;&nbsp;Iterator i = cart.getItems().iterator();&nbsp;&nbsp;while (i.hasNext()) {&nbsp;&nbsp;&nbsp;&nbsp;ShoppingCartItem item =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(ShoppingCartItem)i.next();&nbsp;&nbsp;&nbsp;&nbsp;...%&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td align=&quot;right&quot; bgcolor=&quot;#ffffff&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;${item.quantity}&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;...&lt;% &nbsp;&nbsp;} %&gt;<a name="wp69282"> </a></pre></div><a name="wp69279"> </a><p class="pBody">Flow control tags eliminate the need for scriptlets. The next two sections have examples that demonstrate the conditional and iterator tags.</p><a name="wp73410"> </a><h4 class="pHeading3">Conditional Tags</h4><a name="wp73411"> </a><p class="pBody">The <code class="cCode">if</code> tag allows the conditional execution of its body according to value of a test attribute. The following example from <code class="cCode"><a  href="../examples/web/bookstore4/web/bookcatalog.txt" target="_blank">bookcatalog.jsp</a></code> tests whether the request parameter <code class="cCode">Add</code> is empty. If the test evaluates to <code class="cCode">true</code>, the page queries the database for the book record identified by the request parameter and adds the book to the shopping cart:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;c:if test=&quot;${!empty param.Add}&quot;&gt;&nbsp;&nbsp;&lt;c:set var=&quot;bid&quot; value=&quot;${param.Add}&quot;/&gt;&nbsp;&nbsp;&lt;jsp:useBean id=&quot;bid&quot;  type=&quot;java.lang.String&quot; /&gt;&nbsp;&nbsp; &lt;sql:query var=&quot;books&quot; &nbsp;&nbsp;&nbsp;&nbsp;dataSource=&quot;${applicationScope.bookDS}&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;select * from PUBLIC.books where id = ?&nbsp;&nbsp;&nbsp;&nbsp;&lt;sql:param value=&quot;${bid}&quot; /&gt;&nbsp;&nbsp;&lt;/sql:query&gt;&nbsp;&nbsp;&lt;c:forEach var=&quot;bookRow&quot; begin=&quot;0&quot; items=&quot;${books.rows}&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:useBean id=&quot;bookRow&quot; type=&quot;java.util.Map&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:useBean id=&quot;addedBook&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class=&quot;database.BookDetails&quot; scope=&quot;page&quot; /&gt;&nbsp;&nbsp;...

⌨️ 快捷键说明

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