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

📄 gettingstarted.html

📁 struts 应用研究 struts 应用研究
💻 HTML
字号:
<html><head><title>Getting Started</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body bgcolor="#FFFFFF"><h1>Getting Started with the Standard Taglib</h1><p>This document describes how to get up and running quickly with theStandard Taglib, an implementation of the Java Server Pages&#153; StandardTag Library (JSTL). This document may be useful to page authors and tagdevelopers who are interested in JSTL's functionality.  Using the"standard-examples" application is also a great way to familiarizeyourself with JSTL's functionality and use.</p><hr /><h2>Introduction</h2><a name="#1.1" /></a><h3>What is JSTL?  Where does it come from?</h3><p>JSTL is the Java Server Pages Standard Tag Library.  It is aneffort of the Java Community Process (JCP) and comes out of theJSR-052 expert group.</p><a name="#1.2" /></a><h3>What does JSTL do?</h3><p>JSTL encapsulates, as simple tags, core functionality common to manyJSP applications.  For example, instead of suggesting that you iterateover lists using a scriptlet or different iteration tags fromnumerous vendors, JSTL defines a standard &lt;forEach&gt; tag that worksthe same everywhere.</p><p>This standardization lets you learn a single tag and use it on multipleJSP containers.  Also, when tags are standard, containers can recognizethem and optimize their implementations.</p><p>JSTL provides support for core iterationand control-flow features, text inclusion, internationalizaton-capableformatting tags, and XML-manipulation tags.  It also supports an<i>expression language</i> to simplify page development.Developers may also be interested in JSTL's current extensibilitymechanisms; JSTL currently provides a framework for integrating customtags with JSTL tags.</p><h3>What has changed in this Standard taglib release?</h3><p>Please see the <a href="ReleaseNotes.html">Release Notes</a> document for   information on any release changes.</p><h3>How can I learn more about JSTL</h3><p>Sun's official JSTL page at <ahref="http://java.sun.com/products/jstl">http://java.sun.com/products/jstl</a> lists books and otherresources that will help you learn JSTL.</p><p>&nbsp;</p><hr /><h2><a name="#2" /></a>Getting started quickly</h2><p>The Standard Taglib uses features provided only by the JSP 1.2specification, so it requires a JSP 1.2 container. We recommend youtest the Standard Taglib with Tomcat 4.0.</p><p>To install Tomcat, follow the instructions at <ahref="http://jakarta.apache.org/tomcat">http://jakarta.apache.org/tomcat</a>.To install the Standard Taglib for use in a web application, follow theinstructions at <a href="http://jakarta.apache.org/taglibs/binarydist.html">http://jakarta.apache.org/taglibs/binarydist.html</a>.  You can also usethe "standard-examples" application as a guide.</p><p>To use the Standard Taglib from its Jakarta Taglibs distribution,simply copy the JAR files in the distribution's 'lib' directory to yourapplication's WEB-INF/lib directory. The following JAR files are included in the Standard Taglib distribution and need to be copied to your application's WEB-INF/lib directory:</p>  <table width="95%" border="1" cellpadding="5">    <tr>      <th width="25%">Name</th>      <th width="40%">Description</th>      <th width="35%">Jar File Name</th>    </tr>    <tr>      <td width="25%">        <div align="center"><a href="http://java.sun.com/products/jstl">JSTL          1.0 API classes</a></div>      </td>      <td width="40%">        <div align="left">JSTL 1.0 API classes</div>      </td>      <td width="35%">        <div align="center">jstl.jar</div>      </td>    </tr>    <tr>      <td width="25%">        <div align="center"><a href="http://java.sun.com/products/jstl">JSTL          1.0 implementation classes</a></div>      </td>      <td width="40%">        <div align="left">Standard Taglib JSTL implementation classes</div>      </td>      <td width="35%">        <div align="center">standard.jar</div>      </td>    </tr>    <tr>      <td width="25%">        <div align="center"><a href="http://www.jaxen.org">Jaxen 1.0</a></div>      </td>      <td width="40%">        <div align="left">Xpath engine capable of evaluating Xpath expressions.</div>      </td>      <td width="35%">        <div align="center">jaxen-full.jar</div>      </td>    </tr>    <tr>      <td width="25%">        <div align="center"><a href="http://www.saxpath.org">Saxpath 1.0</a></div>      </td>      <td width="40%">        <div align="left">Simple API for Xpath providing a single point for Xpath          expression parsing.</div>      </td>      <td width="35%">        <div align="center">saxpath.jar</div>      </td>    </tr>    <tr>      <td width="25%">        <div align="center"><a href="http://java.sun.com/products/jdbc/download.html">JDBC          2.0 Optional Package </a></div>      </td>      <td width="40%">        <div align="left">          <p>JDBC implementation classes. </p>          <p>Already present in J2SE 1.4.</p>        </div>      </td>      <td width="35%">        <div align="center">jdbc2_0-stdext.jar</div>      </td>    </tr>    <tr>      <td width="25%">        <div align="center"><a href="http://java.sun.com/products/xml/jaxp">JAXP          1.1 or JAXP 1.2 implementation</a></div>      </td>      <td width="40%">        <div align="left">Standard Taglib requires a JAXP 1.1          or 1.2 compliant parser</div>      </td>      <td width="35%">        <div align="center">          <table width="95%" border="0" align="center">            <tr>              <td width="79%"><font size="-1">example of JAXP 1.1 impl classes</font></td>              <td width="21%">                <div align="left">                  <ul>                    <li>crimson.jar</li>                  </ul>                </div>              </td>            </tr>            <tr>              <td colspan="2" height="22">                <hr>              </td>            </tr>            <tr>              <td width="79%"><font size="-1">example of JAXP 1.2 impl classes</font></td>              <td width="21%">                <ul>                  <li>jaxp-api.jar</li>                  <li>dom.jar</li>                  <li>sax.jar</li>                  <li>xercesImpl.jar</li>                </ul>              </td>            </tr>          </table>        </div>      </td>    </tr>    <tr>      <td width="25%">        <div align="center"><a href="http://xml.apache.org">Xalan</a></div>      </td>      <td width="40%">        <p>Apache XML Xalan XSLT<br>          Transformation Processor.<br>        </p>        <p> If you are using a version of Xalan 2.2.D12 or later you will also          need to obtain the xml-apis.jar which contains the JAXP APIs<br>        </p>      </td>      <td width="35%">        <div align="center">xalan.jar</div>      </td>    </tr>  </table><h3>Multiple tag libraries</h3><p>The constituent tag libraries of Standard Taglib are as follows:</p>  <table border="1" cellpadding="5">    <tr>       <th>Funtional Area</th>      <th>URI</th>      <th>Prefix</th>      <th>Example</th>    </tr>    <tr>       <td>Core</td>      <td>http://java.sun.com/jstl/core</td>      <td>         <div align="center"><font face="Courier New, Courier, mono">c</font></div>      </td>      <td><font face="Courier New, Courier, mono">&lt;c:<i>tagname</i> ...&gt;</font></td>    </tr>    <tr>       <td>XML processing</td>      <td>http://java.sun.com/jstl/xml</td>      <td>         <div align="center"><font face="Courier New, Courier, mono">x</font></div>      </td>      <td><font face="Courier New, Courier, mono">&lt;x:<i>tagname</i> ...&gt;</font></td>    </tr>    <tr>       <td>I18N capable formatting</td>      <td>http://java.sun.com/jstl/fmt</td>      <td>         <div align="center"><font face="Courier New, Courier, mono">fmt</font></div>      </td>      <td><font face="Courier New, Courier, mono">&lt;fmt:<i>tagname</i> ...&gt;</font></td>    </tr>    <tr>       <td>Database access (SQL)</td>      <td>http://java.sun.com/jstl/sql</td>      <td>         <div align="center"><font face="Courier New, Courier, mono">sql</font></div>      </td>      <td><font face="Courier New, Courier, mono">&lt;sql:<i>tagname</i> ...&gt;</font></td>    </tr>  </table><p>Using the Standard Taglib libraries is simple; you simply need to importthem into your JSP pages using the <b>taglib</b> directive.  Forinstance, to import the 'core' JSTL library into your page, you wouldinclude the following line at the top of your JSP page, asfollows:</p><pre>    &lt;%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %&gt;</pre><h3>Expression language</h3><p>Half of JSTL's tags -- the recommended ones -- relyon an expression language. The EL makes it easy for page authors toaccess and manipulate application data.</p><p>For an overview and detailed definition of the default EL see Chapter 3 and Appendix A of the <a href="http://java.sun.com/products/jstl">JSTL 1.0 Specification</a>.</p> <p>Earlier versions of the Standard Taglib used tolet you switch between a number of different expression languages tofacilitate experimentation and feecback. Multiple languages are nolonger supported since a default EL has been decided upon. </p><p><p>The attributes in tags for the EL version of the library do not acceptrtexprvalues.  Instead, you specify literal expressions that the tagsevaluate at runtime.  For example:</p><pre>    &lt;c:forEach items="<b>${page.myItems}</b>" /&gt;</pre><h3>Topics covered in JSTL </h3><p>As we mentioned above, JSTL includes core tags to support iteration,conditionals, and expression-language support. For more information onprecisely how these tags work, you should read the <ahref="http://java.sun.com/products/jstl">JSTL specification</a>.  Here, wejust offer a quick roadmap of each feature in order to help orientyou.</p><dl>   <dt><b>Iteration</b></dt>  <dd>The core iteration tag is &lt;forEach&gt;, which iterates over most collections     and similar objects you'd think to iterate over. &lt;forTokens&gt; lets you     iterate over tokens in a <tt>String</tt> object; it lets you specify the <tt>String</tt>     and the delimiters.</dd>  <dt><b>Conditionals</b></dt>  <dd>JSTL supports a simple conditional &lt;if&gt; tag along with a collection     of tags -- &lt;choose&gt;, &lt;when&gt;, and &lt;otherwise&gt; -- that support     mutually exclusive conditionals. These latter three tags let you implement     a typical <tt>if/else if/else if/else</tt> structure.</dd>  <dt> <b>Expression languages</b></dt>  <dd>JSTL provides a few tags to facilitate use of expression languages. &lt;out&gt;     prints out the value of a particular expression in the current EL, similar     to the way that the scriptlet expression (&lt;%= ... %&gt;) syntax prints     out the value of a expression in the scripting language (typically Java).     &lt;set&gt; lets you set a scoped attribute (e.g., a value in the request,     page, session, or application scopes) with the value of an expression.</dd>  <dt> <b>Text inclusion</b></dt>  <dd>JSP supports the <tt>jsp:include</tt> tag, but this standard action is limited     in that it only supports relative URLs. JSTL introduces the <tt>c:import</tt>     tag, which lets you retrieve absolute URLs. For instance, you can use <tt>c:import</tt>     to retrieve information from the web using HTTP URLs, or from a file server     using an FTP URL. The tag also has some advanced support for performance optimizations,     avoiding unnecessary buffering of data that's retrieved.</dd>  <dt> <b>I18N-capable text formatting</b></dt>  <dd>Formatting data is one of the key tasks in many JSP pages. JSTL introduces     tags to support data formatting and parsing. These tags rely on convenient     machinery to support internationalized applications. </dd>  <dt> <b>XML manipulation</b></dt>  <dd>You can't look anywhere these days without seeing XML, and JSTL gives you     convenient support for manipulating it from your JSP pages. Parse documents,     use XPath to select content, and perform XSLT transformations from within     your JSP pages.</dd>  <dt><b>Database access</b></dt>  <dd>Easily access relational databases using the SQL actions. You can perform database queries, easily access results, perform updates, and group several operations into a transaction.</dd>  <dt>&nbsp;</dt></dl><h3>For tag developers...</h3><p>Developers of custom tags should also read the <ahref="http://java.sun.com/products/jstl">JSTL specification</a>. JSTLdefines some abstract classes that assist with rapid development of tagsand promote integration of custom tags with JSTL's tag set.</p><p>For instance, custom tags can use JSTL's expression-languagemechanism.  As another example, extending<tt>javax.servlet.jsp.jstl.core.ConditionalTagSupport</tt> lets you write aconditional tag by merely implementing a single method that returns a<tt>boolean</tt> value correspondent with your tag's desired conditionalbehavior; also, this base class promotes JSTL's recommended model ofconditional-tag design.</p><p>Similarly, <tt>javax.servlet.jsp.jstl.core.IteratorTagSupport</tt> letsyou easily implement iteration tags.  The handlers for the &lt;forEach&gt;and &lt;forTokens&gt; tags extend this class and thus implement the<tt>javax.servlet.jsp.jstl.core.IteratorTag</tt> interface, which providesa well-defined mechanism for iteration tags to communicate with customsubtags you can write.  See the "standard-examples" application for oneexample of how you might use such custom subtags.</p><h3>Books</h3><p>Several books on JSTL are available or will be available shortly:</p><ul><li><a href="http://jstlbook.com/"><i>JSTL in Action</i></a>, Shawn Bayern, Manning</li><li><a href="http://TheJSPBook.com/"><i>JavaServer Pages</i></a>, Hans Bergsten, O'Reilly</li><li><a href="http://www.core-jstl.com"><i>Core JSTL: Mastering the JSP Standard Tag Library</i></a>, David Geary, Sun Microsystems Press</li></UL></body></html>

⌨️ 快捷键说明

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