📄 jspintro7.html
字号:
<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>'<code class="cCode">mycom.productId</code>'<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["host"]}</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['javax.servlet.<br />forward.servlet_path']}</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 <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"><%@ taglib prefix="f" uri="/functions"%>... <c:when test="${f:equals(selectedLocaleString, localeString)}" ><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 { ... public static boolean equals( String l1, String l2 ) { return l1.equals(l2); }}<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"><function> <name>equals</name> <function-class>mypkg.MyLocales</function-class> <function-signature>boolean equals( java.lang.String, java.lang.String )</function-signature></function><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 + -