﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Samuel LearningStruts1学习</title><link>http://www.blogjava.net/nobody_am/category/33160.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 25 Jul 2008 07:05:36 GMT</lastBuildDate><pubDate>Fri, 25 Jul 2008 07:05:36 GMT</pubDate><ttl>60</ttl><item><title>哪些JSTL可以取代Struts-EL</title><link>http://www.blogjava.net/nobody_am/news/2008/07/25/217324.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Thu, 24 Jul 2008 16:57:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/25/217324.html</guid><description><![CDATA[<table border="1">
    <thead>
        <tr valign="top">
            <th class="th" scope="col" align="left" width="30%">
            <p class="table-para">Struts Tag Library</p>
            </th>
            <th class="th" scope="col" align="left" width="25%">
            <p class="table-para">Tag</p>
            </th>
            <th class="th" scope="col" align="left" width="44%">
            <p class="table-para">JSTL Replacement</p>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Bean</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">cookie</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:set</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Bean</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">define</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:set</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Bean</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">header</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:set</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Bean</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">include</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:import</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Bean</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">parameter</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:set</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Bean</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">write</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:out</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Logic</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">empty</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:if, c:when</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Logic</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">equal</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:if, c:when</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Logic</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">greaterEqual</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:if, c:when</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Logic</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">greaterThan</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:if, c:when</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Logic</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">iterate</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:forEach</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Logic</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">lessEqual</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:if, c:when</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Logic</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">lessThan</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:if, c:when</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Logic</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">notEmpty</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:if, c:when</p>
            </td>
        </tr>
        <tr valign="top">
            <td class="td" align="left" width="30%">
            <p class="table-para">Logic</p>
            </td>
            <td class="td" align="left" width="25%">
            <p class="table-para">notEqual</p>
            </td>
            <td class="td" align="left" width="44%">
            <p class="table-para">c:if, c:when</p>
            </td>
        </tr>
    </tbody>
</table>
<br />
<div class="section">
<h3 class="sect3-title"><a name="905"></a><a name="wbp21Chapter"></a>JSTL Replacement Examples</h3>
<p class="first-para">The following sections provide examples for replacing Struts tag library tags with their JSTL equivalents. Remember that not all the Bean, HTML, and Logic tags can be replaced by JSTL tags.</p>
<div class="section">
<h4 class="sect4-title"><a name="906"></a><a name="wbp21Chapter"></a>bean:cookie Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">cookie</strong> tag from the Bean Tag Library:</p>
<pre class="programlisting">&lt;bean:cookie id="category" name="cat"/&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:set var="category" value="${cookie['cat'].value}"/&gt;</pre>
<p class="last-para">This example accesses the <strong class="bold">cat</strong> cookie with a JSTL expression that makes use of the JSTL implicit <strong class="bold">cookie</strong> object.</p>
</div>
<div class="section">
<h4 class="sect4-title"><a name="907"></a><a name="wbp21Chapter"></a>bean:define Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">define</strong> tag from the Bean Tag Library:</p>
<pre class="programlisting">&lt;bean:define id="name" name="nameObj"/&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:set var="name" value="${nameObj}"/&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="908"></a><a name="wbp21Chapter"></a>bean:header Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">header</strong> tag from the Bean Tag Library:</p>
<pre class="programlisting">&lt;bean:header id="browser" name="User-Agent"/&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:set var="browser" value="${header['User-Agent']}"/&gt;</pre>
<p class="last-para">This example accesses the "User-Agent" header with a JSTL expression that makes use of the JSTL implicit <strong class="bold">header</strong> object.</p>
</div>
<div class="section">
<h4 class="sect4-title"><a name="909"></a><a name="wbp21Chapter"></a>bean:include Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">include</strong> tag from the Bean Tag Library:</p>
<div class="widecontent">
<pre class="programlisting">&lt;bean:include id="yahooContents" href="http://www.yahoo.com/"/&gt;<a name="910"></a><a name="beginpage."></a>
</pre>
</div>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:import var="yahooContents" url=" http://www.yahoo.com/"/&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="911"></a><a name="wbp21Chapter"></a>bean:parameter Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">parameter</strong> tag from the Bean Tag Library:</p>
<pre class="programlisting">&lt;bean:parameter id="color" name="clr"/&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:set var="color" value="${param['clr']}"/&gt;</pre>
<p class="last-para">This example accesses the <strong class="bold">clr</strong> parameter with a JSTL expression that makes use of the JSTL implicit <strong class="bold">param</strong> object.</p>
</div>
<div class="section">
<h4 class="sect4-title"><a name="912"></a><a name="wbp21Chapter"></a>bean:write Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">write</strong> tag from the Bean Tag Library:</p>
<pre class="programlisting">&lt;bean:write name="bizObj"/&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:out value="${bizObj}" /&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="913"></a><a name="wbp21Chapter"></a>logic:empty Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">empty</strong> tag from the Logic Tag Library:</p>
<pre class="programlisting">&lt;logic:empty name="results"&gt;
Your search yielded no results.
&lt;/logic:empty&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:if test="${empty results}"&gt;
Your search yielded no results.
&lt;/c:if&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="914"></a><a name="wbp21Chapter"></a>logic:equal Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">equal</strong> tag from the Logic Tag Library:</p>
<pre class="programlisting">&lt;logic:equal name="count" value="0"&gt;
Count is zero.
&lt;/logic:equal&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:if test="${count == 0}"&gt;
Count is zero.
&lt;/c:if&gt;<a name="915"></a><a name="beginpage."></a>
</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="916"></a><a name="wbp21Chapter"></a>bean:greaterEqual Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">greaterEqual</strong> tag from the Logic Tag Library:</p>
<pre class="programlisting">&lt;logic:greaterEqual name="count" value="5"&gt;
Count is greater than or equal to five.
&lt;/logic:greaterEqual&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:if test="${count &gt;= 5}"&gt;
Count is greater than or equal to five.
&lt;/c:if&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="917"></a><a name="wbp21Chapter"></a>logic:greaterThan Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">greaterThan</strong> tag from the Logic Tag Library:</p>
<pre class="programlisting">&lt;logic:greaterThan name="count" value="5"&gt;
Count is greater than five.
&lt;/logic:greaterThan&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:if test="${count &gt; 5}"&gt;
Count is greater than five.
&lt;/c:if&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="918"></a><a name="wbp21Chapter"></a>logic:iterate Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">iterate</strong> tag from the Logic Tag Library:</p>
<pre class="programlisting">&lt;logic:iterate id="result" collection="&lt;%=results%&gt;"&gt;
Result: &lt;%=result%&gt;&lt;br&gt;
&lt;/logic:iterate&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:forEach var="result" items="${results}"&gt;
Result: &lt;c:out value="${result}"/&gt;
&lt;/c:forEach&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="919"></a><a name="wbp21Chapter"></a>logic:lessEqual Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">lessEqual</strong> tag from the Logic Tag Library:</p>
<pre class="programlisting">&lt;logic:lessEqual name="count" value="5"&gt;
Count is less than or equal to five.
&lt;/logic:lessEqual&gt;</pre>
<p class="para">The JSTL equivalent is as follows:<a name="920"></a><a name="beginpage."></a> </p>
<pre class="programlisting">&lt;c:if test="${count &lt;= 5}"&gt;
Count is less than or equal to five.
&lt;/c:if&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="921"></a><a name="wbp21Chapter"></a>logic:lessThan Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">lessThan</strong> tag from the Logic Tag Library:</p>
<pre class="programlisting">&lt;logic:lessThan name="count" value="5"&gt;
Count is less than five.
&lt;/logic:lessThan&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:if test="${count &lt; 5}"&gt;
Count is less than five.
&lt;/c:if&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="922"></a><a name="wbp21Chapter"></a>logic:notEmpty Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">notEmpty</strong> tag from the Logic Tag Library:</p>
<pre class="programlisting">&lt;logic:notEmpty name="results"&gt;
Your search returned results!
&lt;/logic:notEmpty&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:if test="${!empty results}"&gt;
Your search returned results!
&lt;/c:if&gt;</pre>
</div>
<div class="section">
<h4 class="sect4-title"><a name="923"></a><a name="wbp21Chapter"></a>logic:notEqual Replacement Example</h4>
<p class="first-para">The following snippet shows the basic usage of the <strong class="bold">notEqual</strong> tag from the Logic Tag Library:</p>
<pre class="programlisting">&lt;logic:notEqual name="count" value="0"&gt;
Count is not equal to zero.
&lt;/logic:notEqual&gt;</pre>
<p class="para">The JSTL equivalent is as follows:</p>
<pre class="programlisting">&lt;c:if test="${count != 0}"&gt;
Count is not equal to zero.
&lt;/c:if&gt;</pre>
</div>
</div>
<br />
<img src ="http://www.blogjava.net/nobody_am/aggbug/217324.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-25 00:57 <a href="http://www.blogjava.net/nobody_am/news/2008/07/25/217324.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>