📄 jspintro9.html
字号:
The <code class="cCode">iterator</code> example defines and uses a simple iteration tag. The JSP pages use a logical name to reference the TLD. A sample <code class="cCode">iterator.war</code> is provided in <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/web/provided-wars/</code>. To build and package the example:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp82029"> </a><div class="pSmartList1"><li>In a terminal window, go to <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/web/iterator/</code>.</li></div><a name="wp84478"> </a><div class="pSmartList1"><li>Run <code class="cCode">asant</code> <code class="cCode">build</code>. This target will spawn any necessary compilations and copy files to the <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/web/iterator/build/</code> directory. </li></div><a name="wp97183"> </a><div class="pSmartList1"><li>Start <code class="cCode">deploytool</code>. </li></div><a name="wp97184"> </a><div class="pSmartList1"><li>Create a Web application called <code class="cCode">iterator</code> by running the New Web Component Wizard. Select File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Web Component.</li></div><a name="wp97185"> </a><div class="pSmartList1"><li>New Web Component Wizard</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp97186"> </a><div class="pSmartList2"><li>Select the Create New Stand-Alone WAR Module radio button.</li></div><a name="wp97187"> </a><div class="pSmartList2"><li>Click Browse.</li></div><a name="wp97188"> </a><div class="pSmartList2"><li>In the WAR Location field, enter <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/docs/tutorial/examples/web/iterator/iterator.war</code>. </li></div><a name="wp97189"> </a><div class="pSmartList2"><li>In the WAR Name field, enter <code class="cCode">iterator</code>.</li></div><a name="wp97190"> </a><div class="pSmartList2"><li>In the Context Root field, enter <code class="cCode">/iterator</code>.</li></div><a name="wp97191"> </a><div class="pSmartList2"><li>Click Edit. In the Edit Contents dialog, navigate to <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/docs/tutorial/examples/web/iterator/build/</code>. Select the <code class="cCode">index.jsp</code> and <code class="cCode">list.jsp</code> JSP pages and <code class="cCode">iterator.tld </code>and click Add. Notice that <code class="cCode">iterator.tld</code> is put into <code class="cCode">/WEB-INF/</code>.</li></div><a name="wp97192"> </a><div class="pSmartList2"><li>Click Next.</li></div><a name="wp97193"> </a><div class="pSmartList2"><li>Select the JSP radio button. </li></div><a name="wp97194"> </a><div class="pSmartList2"><li>Click Next.</li></div><a name="wp97195"> </a><div class="pSmartList2"><li>Select <code class="cCode">index.jsp</code> from the JSP file combo box. </li></div><a name="wp97196"> </a><div class="pSmartList2"><li>Click Finish.</li></div></ol></div></ol></div><a name="wp97206"> </a><p class="pBody">You map a logical name to an absolute location in the Web application deployment descriptor. To specifyThe iterator example specifies the mapping of the logical name <code class="cCode">/tlt</code> to the absolute location <code class="cCode">/WEB-INF/iterator.tld</code>with <code class="cCode">deploytool</code>:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp97207"> </a><div class="pSmartList1"><li>Select the File Refs tab.</li></div><a name="wp97208"> </a><div class="pSmartList1"><li>Click the Add button in the JSP Tag Libraries tab.</li></div><a name="wp97209"> </a><div class="pSmartList1"><li>Enter the relative URI <code class="cCode">/tlt </code>in the Coded Reference field.</li></div><a name="wp97210"> </a><div class="pSmartList1"><li>Enter the absolute location <code class="cCode">/WEB-INF/iterator.tld</code> in the Tag Library field.</li></div></ol></div><a name="wp85808"> </a><p class="pBody">You can also reference a TLD in a <code class="cCode">taglib</code> directive with an absolute URI. For example, the absolute URIs for the JSTL library are:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp73341"> </a><div class="pSmartList1"><li>Core: <code class="cCode">http://java.sun.com/jsp/jstl/core</code></li></div><a name="wp73342"> </a><div class="pSmartList1"><li>XML: <code class="cCode">http://java.sun.com/jsp/jstl/xml</code></li></div><a name="wp73343"> </a><div class="pSmartList1"><li>Internationalization: <code class="cCode">http://java.sun.com/jsp/jstl/fmt</code></li></div><a name="wp83319"> </a><div class="pSmartList1"><li>SQL: <code class="cCode">http://java.sun.com/jsp/jstl/sql</code></li></div><a name="wp83320"> </a><div class="pSmartList1"><li>Functions: <code class="cCode">http://java.sun.com/jsp/jstl/functions</code></li></div></ul></div><a name="wp73345"> </a><p class="pBody">When you reference a tag library with an absolute URI that exactly matches the URI declared in the <code class="cCode">taglib</code> element of the TLD (see <a href="JSPTags6.html#wp90086">Tag Library Descriptors</a>), you do not have to add the <code class="cCode">taglib</code> element to <code class="cCode">web.xml</code>; the JSP container automatically locates the TLD inside the JSTL library implementation. </p><a name="wp73346"> </a><h3 class="pHeading2">Including the Tag Library Implementation</h3><a name="wp82819"> </a><p class="pBody">In addition to declaring the tag library, you also need to make the tag library implementation available to the Web application. There are several ways to do this. Tag library implementations can be included in a WAR in an unpacked format: tag files are packaged in the <code class="cCode">/WEB-INF/tag/</code> directory and tag handler classes are packaged in the <code class="cCode">/WEB-INF/classes/</code> directory of the WAR. Tag libraries already packaged into a JAR file are included in the <code class="cCode">/WEB-INF/lib/</code> directory of the WAR. Finally, an application server may load a tag library into all the Web applications running on the server. For example, in the J2EE 1.4 Application Server, the JSTL TLDs <code class="cCode">and </code>libraries are distributed in the archive<code class="cCode">appserv-jstl.jar</code> in <code class="cCode"><</code><code class="cVariable">J2EE_HOME</code><code class="cCode">>/lib/</code>.This library is automatically loaded into the classpath of all Web applications running on the J2EE application server so you don't need to add it to your Web application. </p><a name="wp97314"> </a><p class="pBody">To package the <code class="cCode">iterator</code> tag library implementation in the <code class="cCode">/WEB-INF/classes/ </code>directory and deploy the <code class="cCode">iterator</code> example with <code class="cCode">deploytool</code>:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp97315"> </a><div class="pSmartList1"><li>Select the General tab.</li></div><a name="wp97316"> </a><div class="pSmartList1"><li>Click Edit. </li></div><a name="wp97317"> </a><div class="pSmartList1"><li>Add the iterator tag library classes. </li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp97318"> </a><div class="pSmartList2"><li>In the Edit Contents dialog, navigate to <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/docs/tutorial/examples/web/iterator/build/</code>.</li></div><a name="wp97319"> </a><div class="pSmartList2"><li>Select the <code class="cCode">iterator</code> and <code class="cCode">myorg </code>packages and click Add. Notice that the tag library implementation classes are packaged into <code class="cCode">/WEB-INF/classes/</code>.</li></div></ol></div><a name="wp97320"> </a><div class="pSmartList1"><li>Click OK.</li></div><a name="wp97321"> </a><div class="pSmartList1"><li>Select File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Save.</li></div><a name="wp97322"> </a><div class="pSmartList1"><li>Start the J2EE application server.</li></div><a name="wp97323"> </a><div class="pSmartList1"><li>Deploy the application. </li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp97324"> </a><div class="pSmartList2"><li>Select Tools<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Deploy. </li></div><a name="wp97326"> </a><div class="pSmartList2"><li>Click OK.</li></div></ol></div></ol></div><a name="wp86141"> </a><p class="pBody">To run the <code class="cCode">iterator</code> application, open the URL <code class="cCode">http://localhost:8080/iterator</code> in a browser.</p> </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="JSPIntro8.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="JSPIntro10.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 + -