📄 jsptags3.html
字号:
<?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>The Example JSP Pages</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="JSPTags2.html" /> <link rel="Next" href="JSPTags4.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="JSPTags2.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="JSPTags4.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="wp89456"> </a><h2 class="pHeading1">The Example JSP Pages</h2><a name="wp89457"> </a><p class="pBody">This chapter describes the tasks involved in defining tags. The chapter illustrates the tasks with excerpts from the JSP version of the Duke's Bookstore application discussed in <a href="JSPIntro3.html#wp83415">The Example JSP Pages</a> rewritten to take advantage of several new custom tags:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp89462"> </a><div class="pSmartList1"><li>A <code class="cCode">catalog</code> tag for rendering the book catalog</li></div><a name="wp89463"> </a><div class="pSmartList1"><li>A <code class="cCode">shipDate</code> tag for rendering the ship date of an order</li></div><a name="wp89464"> </a><div class="pSmartList1"><li>A template library for ensuring a common look and feel among all screens and composing screens out of content chunks</li></div></ul></div><a name="wp89468"> </a><p class="pBody">The last section in the chapter, <a href="JSPTags7.html#wp90673">Examples</a>, describes several tags in detail: a simplified iteration tag and the set of tags in the <code class="cCode">tutorial-template</code> tag library.</p><a name="wp89470"> </a><p class="pBody">The <code class="cCode">tutorial-template</code> tag library defines a set of tags for creating an application template. The template is a JSP page with placeholders for the parts that need to change with each screen. Each of these placeholders is referred to as a parameter of the template. For example, a simple template could include a title parameter for the top of the generated screen and a body parameter to refer to a JSP page for the custom content of the screen. The template is created with a set of nested tags--<code class="cCode">definition</code>, <code class="cCode">screen</code>, and <code class="cCode">parameter</code>--that are used to build a table of screen definitions for Duke's Bookstore and with an <code class="cCode">insert</code> tag to insert parameters from the table into the screen.</p><a name="wp89474"> </a><p class="pBody"><a href="JSPTags3.html#wp89493">Figure 15-1</a> shows the flow of a request through the following Duke's Bookstore Web components:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp89476"> </a><div class="pSmartList1"><li><code class="cCode"><a href="../examples/web/bookstore3/web/template/template.txt" target="_blank">template.jsp</a></code>, which determines the structure of each screen. It uses the <code class="cCode">insert</code> tag to compose a screen from subcomponents.</li></div><a name="wp89478"> </a><div class="pSmartList1"><li><code class="cCode"><a href="../examples/web/bookstore3/web/template/screendefinitions.txt" target="_blank">screendefinitions.jsp</a></code>, which defines the subcomponents used by each screen. All screens have the same banner, but different title and body content (specified by the JSP Page column in <a href="JSPIntro3.html#wp65822">Table 12-1</a>).</li></div><a name="wp89483"> </a><div class="pSmartList1"><li><code class="cCode"><a href="../examples/web/bookstore3/src/Dispatcher.java" target="_blank">Dispatcher</a></code>, a servlet, which processes requests and forwards to <code class="cCode">template.jsp</code>.</li></div></ul></div><a name="wp89491"> </a><p class="pBody"></p><div align="left"><img src="images/Fig31.gif" height="308" width="397" alt="Request Flow Through Duke's Bookstore Components" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><p> <a name="89493"> </a><strong><font >Figure 15-1 Request Flow Through Duke's Bookstore Components</font></strong></p><a name="wp89494"> </a><p class="pBody">The source code for the Duke's Bookstore application is located in the <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/web/bookstore3/</code> directory created when you unzip the tutorial bundle (see <a href="About.html#wp63740">About the Examples</a>). A sample <code class="cCode">bookstore3.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, package, deploy, and run the example:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp89500"> </a><div class="pSmartList1"><li>Build and package the bookstore common files as described in <a href="WebApp11.html#wp64678">Configuring Web Modules</a>. </li></div><a name="wp89502"> </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/bookstore3/</code>.</li></div><a name="wp89503"> </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/bookstore3/build/</code> directory. </li></div><a name="wp89504"> </a><div class="pSmartList1"><li>Start the J2EE application server.</li></div><a name="wp89507"> </a><div class="pSmartList1"><li>Perform all the operations described in <a href="WebApp13.html#wp69868">Accessing Databases from Web Applications</a>.</li></div><a name="wp92225"> </a><div class="pSmartList1"><li>Start <code class="cCode">deploytool</code>. </li></div><a name="wp92226"> </a><div class="pSmartList1"><li>Create a Web application called <code class="cCode">bookstore3</code>. </li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp92227"> </a><div class="pSmartList2"><li>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="wp92228"> </a><div class="pSmartList2"><li>Select the Create New Stand-Alone WAR Module radio button.</li></div><a name="wp92229"> </a><div class="pSmartList2"><li>Click Browse.</li></div><a name="wp92230"> </a><div class="pSmartList2"><li>In the WAR Location field, enter <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/web/bookstore3/bookstore3.war</code>. </li></div><a name="wp92231"> </a><div class="pSmartList2"><li>In the WAR Name field, enter <code class="cCode">bookstore3</code>.</li></div></ol></div><a name="wp92232"> </a><div class="pSmartList1"><li>Add Web application files and libraries. </li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp92233"> </a><div class="pSmartList2"><li>Click Edit.</li></div><a name="wp92234"> </a><div class="pSmartList2"><li>Add the application content. In the Edit Contents dialog, navigate to <code class="cCode"><</code><code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/web/bookstore3/build/</code>. Select the JSP pages <code class="cCode">bookstore.jsp</code>, <code class="cCode">bookdetails.jsp</code>, <code class="cCode">bookcatalog.jsp</code>, <code class="cCode">bookshowcart.jsp</code>, <code class="cCode">bookcashier.jsp</code>, <code class="cCode">bookreceipt.jsp</code>, <code class="cCode">bookordererror.jsp,</code> the tag files <code class="cCode">catalog.tag</code> and <code class="cCode">shipDate.tag</code> and the <code class="cCode">dispatcher</code>, <code class="cCode">database</code>, <code class="cCode">listeners</code>, and <code class="cCode">template</code> directories and click Add. Click OK.</li></div><a name="wp92235"> </a><div class="pSmartList2"><li>Add the shared bookstore library. Navigate to<code class="cCode"> <</code><code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/build/web/bookstore/dist/</code>. Select <code class="cCode">bookstore.jar</code> and Click Add.</li></div>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -