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

📄 jspintro7.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
  <tr align="left">    <td><a name="wp77123"> </a><div class="pCellBody"><code class="cCode">${3 div 4}</code></div></td>    <td><a name="wp77125"> </a><div class="pCellBody"><code class="cCode">0.75</code></div></td></tr>  <tr align="left">    <td><a name="wp77127"> </a><div class="pCellBody"><code class="cCode">${10 mod 4}</code></div></td>    <td><a name="wp77129"> </a><div class="pCellBody"><code class="cCode">2</code></div></td></tr>  <tr align="left">    <td><a name="wp77286"> </a><div class="pCellBody"><code class="cCode">${!empty param.Add}</code></div></td>    <td><a name="wp77288"> </a><div class="pCellBody">True if the request parameter named <code class="cCode">Add</code> is null or an empty string<code class="cCode">.</code></div></td></tr>  <tr align="left">    <td><a name="wp77245"> </a><div class="pCellBody"><code class="cCode">${pageContext.request.contextPath}</code></div></td>    <td><a name="wp77247"> </a><div class="pCellBody">The context path</div></td></tr>  <tr align="left">    <td><a name="wp77241"> </a><div class="pCellBody"><code class="cCode">${sessionScope.cart.numberOfItems}</code></div></td>    <td><a name="wp77243"> </a><div class="pCellBody">The value of the <code class="cCode">numberOfItems</code> property of the session-scoped attribute named <code class="cCode">cart</code></div></td></tr>  <tr align="left">    <td><a name="wp77237"> </a><div class="pCellBody"><code class="cCode">${param[</code>&#39;<code class="cCode">mycom.productId</code>&#39;<code class="cCode">]}</code></div></td>    <td><a name="wp77239"> </a><div class="pCellBody">The value of the request parameter named <code class="cCode">mycom.productId</code></div></td></tr>  <tr align="left">    <td><a name="wp77233"> </a><div class="pCellBody"><code class="cCode">${header[&quot;host&quot;]}</code></div></td>    <td><a name="wp77235"> </a><div class="pCellBody">The host</div></td></tr>  <tr align="left">    <td><a name="wp81273"> </a><div class="pCellBody"><code class="cCode">${departments[deptName]}</code></div></td>    <td><a name="wp81275"> </a><div class="pCellBody">The value of the entry named <code class="cCode">deptName</code> in the <code class="cCode">departments</code> map</div></td></tr>  <tr align="left">    <td><a name="wp84339"> </a><div class="pCellBody"><code class="cCode">${requestScope[&#39;javax.servlet.<br />forward.servlet_path&#39;]}</code></div></td>    <td><a name="wp84341"> </a><div class="pCellBody">The value of the request-scoped attribute named <code class="cCode">javax.servlet.<br />forward.servlet_path</code></div></td></tr></table></div><p class="pBody"></p><a name="wp77078"> </a><h3 class="pHeading2">Functions</h3><a name="wp71289"> </a><p class="pBody">The JSP expression language allows you to define a function that can be invoked in an expression. Functions are defined using the same mechanisms as custom tags (See <a  href="JSPIntro9.html#wp73314">Using Custom Tags</a> and Chapter&nbsp;<a  href="JSPTags.html#wp74641">15</a>). </p><a name="wp71290"> </a><h4 class="pHeading3">Using Functions</h4><a name="wp71821"> </a><p class="pBody">Functions can appear in template text and tag attribute values. </p><a name="wp71709"> </a><p class="pBody">To use a function in a JSP page, you import the tag library containing the function using a <code class="cCode">taglib</code> directive. Then, you preface the function invocation with the prefix declared in the directive. </p><a name="wp71718"> </a><p class="pBody">For example, the date example page <code class="cCode">index.jsp</code> imports the <code class="cCode">/functions</code> library and invokes the function <code class="cCode">equals</code> in an expression:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;%@ taglib prefix=&quot;f&quot; uri=&quot;/functions&quot;%&gt;...&nbsp;&nbsp;&nbsp;&nbsp;&lt;c:when&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test=&quot;${f:equals(selectedLocaleString,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;localeString)}&quot; &gt;<a name="wp75108"> </a></pre></div><a name="wp71298"> </a><h4 class="pHeading3">Defining Functions</h4><a name="wp71300"> </a><p class="pBody">To define a function you program it as a public static method in a public class. The <code class="cCode">mypkg.MyLocales</code> class in the <code class="cCode">date</code> example defines a function that tests the equality of two <code class="cCode">Strings</code> as follows:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">package mypkg;public class MyLocales {&nbsp;&nbsp;...&nbsp;&nbsp;public static boolean equals( String l1, String l2 ) {&nbsp;&nbsp;&nbsp;&nbsp;return l1.equals(l2);&nbsp;&nbsp;}}<a name="wp75123"> </a></pre></div><a name="wp71307"> </a><p class="pBody">Then, you map the function name as used in the EL expression to the defining class and function signature in a TLD. The following <code class="cCode">functions.tld</code> file in the date example maps the <code class="cCode">equals</code> function to the class containing the implementation of the function <code class="cCode">equals</code> and the signature of the function:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;function&gt;&nbsp;&nbsp;&lt;name&gt;equals&lt;/name&gt;&nbsp;&nbsp;&lt;function-class&gt;mypkg.MyLocales&lt;/function-class&gt;&nbsp;&nbsp;&lt;function-signature&gt;boolean equals( java.lang.String,&nbsp;&nbsp;&nbsp;&nbsp;java.lang.String )&lt;/function-signature&gt;&lt;/function&gt;<a name="wp75037"> </a></pre></div><a name="wp71919"> </a><p class="pBody">A tag library can only have one <code class="cCode">function</code> element with any given <code class="cCode">name</code> element.</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="JSPIntro6.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="JSPIntro8.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 + -