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

📄 jsptags5.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 4 页
字号:
</caption>  <tr align="center">    <th><a name="wp89931"> </a><div class="pCellHeading">Attribute</div></th>    <th><a name="wp89933"> </a><div class="pCellHeading">Description</div></th></tr>  <tr align="left">    <td><a name="wp89935"> </a><div class="pCellBody"><code class="cCode">description</code></div></td>    <td><a name="wp89937"> </a><div class="pCellBody">(optional) An optional description of this variable. Defaults to no description.</div></td></tr>  <tr align="left">    <td><a name="wp89939"> </a><div class="pCellBody"><code class="cCode">name-given | name-from-attribute</code></div></td>    <td><a name="wp89941"> </a><div class="pCellBody">Defines an EL variable to be used in the page invoking this tag. Either <code class="cCode">name-given</code> or <code class="cCode">name-from-attribute</code> must be specified. If <code class="cCode">name-given</code> is specified, the value is the name of the variable. If <code class="cCode">name-from-attribute</code> is specified, the value is the name of an attribute whose (translation-time) value at of the start of the tag invocation will give the name of the variable. </div><a name="wp89942"> </a><div class="pCellBody">Translation errors arise in the following circumstances:</div><a name="wp89943"> </a><div class="pCellBody">&#160;</div><a name="wp89944"> </a><div class="pCellBody">1. Specifying neither <code class="cCode">name-given</code> or <code class="cCode">name-from-attribute</code> or both. </div><a name="wp89945"> </a><div class="pCellBody">2. If two <code class="cCode">variable</code> directives have the same <code class="cCode">name-given</code>.</div><a name="wp89946"> </a><div class="pCellBody">3. If the value of <code class="cCode">name-given</code> attribute of a <code class="cCode">variable</code> directive is equal to the value of a <code class="cCode">name</code> attribute of an <code class="cCode">attribute</code> directive or the value of <code class="cCode">dynamic-attributes</code> attribute of a <code class="cCode">tag</code> directive.</div></td></tr>  <tr align="left">    <td><a name="wp89948"> </a><div class="pCellBody">alias</div></td>    <td><a name="wp89950"> </a><div class="pCellBody">Defines a variable, local to the tag file, to hold the value of the EL variable. The container will synchronize this value with the variable whose name is given in <code class="cCode">name-from-attribute</code>.</div><a name="wp89951"> </a><div class="pCellBody">&#160;</div><a name="wp89952"> </a><div class="pCellBody">Required when <code class="cCode">name-from-attribute</code> is specified. A translation error results if used without <code class="cCode">name-from-attribute</code>.</div><a name="wp89953"> </a><div class="pCellBody">&#160;</div><a name="wp89954"> </a><div class="pCellBody">A translation error results if the value of <code class="cCode">alias</code> is the same as the value of a <code class="cCode">name</code> attribute of an <code class="cCode">attribute</code> directive or the <code class="cCode">name-given</code> attribute of a <code class="cCode">variable</code> directive.</div></td></tr>  <tr align="left">    <td><a name="wp89956"> </a><div class="pCellBody"><code class="cCode">variable-class</code></div></td>    <td><a name="wp89958"> </a><div class="pCellBody">(optional) The name of the class of the variable. The default is <code class="cCode">java.lang.String</code>.</div></td></tr>  <tr align="left">    <td><a name="wp89960"> </a><div class="pCellBody"><code class="cCode">declare</code></div></td>    <td><a name="wp89962"> </a><div class="pCellBody">(optional) Whether the variable is declared or not. True is the default.</div></td></tr>  <tr align="left">    <td><a name="wp89964"> </a><div class="pCellBody"><code class="cCode">scope</code></div></td>    <td><a name="wp89966"> </a><div class="pCellBody">(optional) The scope of the variable. Can be either <code class="cCode">AT_BEGIN</code>, <code class="cCode">AT_END</code>, or <code class="cCode">NESTED</code>. Defaults to <code class="cCode">NESTED</code>.</div></td></tr></table></div><p class="pBody"></p><a name="wp89968"> </a><h5 class="pHeading4">Variable Synchronization</h5><a name="wp89969"> </a><p class="pBody">The Web container handles the synchronization of variables between a tag file and a calling page. <a  href="JSPTags5.html#wp89980">Table 15-5</a> summarizes when and how each object is synchronized according to the object's scope.</p><div align="left"><table border="1" summary="Variable synchronization behavior" id="wp89980">  <caption><a name="wp89980"> </a><div class="pTableTitle">Table 15-5   Variable Synchronization Behavior&nbsp;</div></caption>  <tr align="center">    <th><a name="wp89988"> </a><div class="pCellHeading">&#160;</div></th>    <th><a name="wp89990"> </a><div class="pCellHeading">AT_BEGIN</div></th>    <th><a name="wp89992"> </a><div class="pCellHeading">NESTED</div></th>    <th><a name="wp89994"> </a><div class="pCellHeading">AT_END</div></th></tr>  <tr align="left">    <td><a name="wp89996"> </a><div class="pCellBody">Beginning of tag file</div></td>    <td><a name="wp89998"> </a><div class="pCellBody">not synch.</div></td>    <td><a name="wp90000"> </a><div class="pCellBody">save</div></td>    <td><a name="wp90002"> </a><div class="pCellBody">not synch.</div></td></tr>  <tr align="left">    <td><a name="wp90004"> </a><div class="pCellBody">Before any fragment invocation via <code class="cCode">jsp:invoke</code> or <code class="cCode">jsp:doBody </code>(see <a  href="JSPTags5.html#wp90043">Evaluating Fragments Passed to Tag Files</a>)</div></td>    <td><a name="wp90009"> </a><div class="pCellBody">tag<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>page</div></td>    <td><a name="wp90011"> </a><div class="pCellBody">tag<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>page</div></td>    <td><a name="wp90013"> </a><div class="pCellBody">not synch</div></td></tr>  <tr align="left">    <td><a name="wp90015"> </a><div class="pCellBody">End of tag file</div></td>    <td><a name="wp90017"> </a><div class="pCellBody">tag<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>page</div></td>    <td><a name="wp90019"> </a><div class="pCellBody">restore</div></td>    <td><a name="wp90021"> </a><div class="pCellBody">tag<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>page</div></td></tr></table></div><p class="pBody"></p><a name="wp90022"> </a><p class="pBody">If <code class="cCode">name-given</code> is used to specify the variable name, the name of the variable in the calling page and the name of the variable in the tag file are the same and are equal to the value of <code class="cCode">name-given</code>. </p><a name="wp90023"> </a><p class="pBody">The <code class="cCode">name-from-attribute</code> and <code class="cCode">alias</code> attributes of the <code class="cCode">variable</code> directive can be used to customize the name of the variable in the calling page while using another name in the tag file. When using these attributes, the name of the variable in the calling page is set from the value of <code class="cCode">name-from-attribute</code> at the time the tag was called. The name of the corresponding variable in the tag file is the value of <code class="cCode">alias</code>.</p><a name="wp90024"> </a><h5 class="pHeading4">Synchronization Examples</h5><a name="wp90025"> </a><p class="pBody">The following examples illustrate how variable synchronization works between a tag file and its calling page. All the example JSP pages and tag files reference the JSTL core tag library with the prefix <code class="cCode">c</code>. The JSP pages reference a tag file located in <code class="cCode">/WEB-INF/tags</code> with the prefix <code class="cCode">my</code>.</p><a name="wp90026"> </a><p class="pDefinitionTerm">AT_BEGIN Scope</p><a name="wp90027"> </a><p class="pBody">In this example, the <code class="cCode">AT_BEGIN</code> scope is used to pass the value of the variable named <code class="cCode">x</code> to the tag's body and at the end of the tag invocation.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;%-- callingpage.jsp --%&gt;&lt;c:set var=&quot;x&quot; value=&quot;1&quot;/&gt;${x} &lt;%-- (<code class="cCodeBold">x == 1</code>) --%&gt;&lt;my:example&gt;&nbsp;&nbsp;${x} &lt;%-- (<code class="cCodeBold">x == 2</code>) --%&gt;&lt;/my:example&gt;${x} &lt;%-- (<code class="cCodeBold">x == 4</code>) --%&gt;<a name="wp90028"> </a>&lt;%-- example.tag --%&gt;&lt;%@ variable name-given=&quot;x&quot; scope=&quot;AT_BEGIN&quot; %&gt;${x} &lt;%-- (x == null) --%&gt;&lt;c:set var=&quot;x&quot; value=&quot;2&quot;/&gt;&lt;jsp:doBody/&gt;${x} &lt;%-- (x == 2) --%&gt;&lt;c:set var=&quot;x&quot; value=&quot;4&quot;/&gt;<a name="wp90029"> </a></pre></div><a name="wp90030"> </a><p class="pDefinitionTerm">NESTED Scope</p><a name="wp90031"> </a><p class="pBody">In this example, the <code class="cCode">NESTED</code> scope is used to make a variable named <code class="cCode">x</code> available only to the tag's body. The tag sets the variable to <code class="cCode">2</code> and this value is passed to the calling page before the body is invoked. Since the scope is <code class="cCode">NESTED</code>, and the calling page also had a variable named <code class="cCode">x</code>, its original value, <code class="cCode">1</code>, is restored when the tag completes.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;%-- callingpage.jsp --%&gt;&lt;c:set var=&quot;x&quot; value=&quot;1&quot;/&gt;${x} &lt;%-- (<code class="cCodeBold">x == 1</code>) --%&gt;&lt;my:example&gt;&nbsp;&nbsp;${x} &lt;%-- (<code class="cCodeBold">x == 2</code>) --%&gt;&lt;/my:example&gt;${x} &lt;%-- (<code class="cCodeBold">x == 1</code>) --%&gt;<a name="wp90032"> </a>&lt;%-- example.tag --%&gt;&lt;%@ variable name-given=&quot;x&quot; scope=&quot;NESTED&quot; %&gt;${x} &lt;%-- (x == null) --%&gt;&lt;c:set var=&quot;x&quot; value=&quot;2&quot;/&gt;&lt;jsp:doBody/&gt;${x} &lt;%-- (x == 2) --%&gt;&lt;c:set var=&quot;x&quot; value=&quot;4&quot;/&gt;<a name="wp90033"> </a></pre></div><a name="wp90034"> </a><p class="pDefinitionTerm">AT_END Scope

⌨️ 快捷键说明

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