📄 struts-logic.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>The Struts Framework Project - Logic Tags</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="Craig R. McClanahan" name="author" />
<link href="../struts.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="heading">
<a href="http://apache.org/">
<img id="asf_logo_wide" alt="The Apache Project" src="../images/asf_logo_wide.gif" />
</a>
<a href="http://struts.apache.org/">
<img id="struts-logo" alt="Struts Framework" src="../images/struts.gif" />
</a>
</div>
<!--end heading-->
<div id="content">
<div id="menu">
<p>User Guide</p>
<ul>
<li>
<a href="index.html">Table of Contents</a>
</li>
<li>
<a href="preface.html">Preface</a>
</li>
<li>
<a href="introduction.html">Introduction</a>
</li>
<li>
<a href="building_model.html">Model Components</a>
</li>
<li>
<a href="building_view.html">View Components</a>
</li>
<li>
<a href="building_controller.html">Controller Components</a>
</li>
<li>
<a href="configuration.html">Configuration</a>
</li>
<li>
<a href="release-notes.html">Release Notes</a>
</li>
<li>
<a href="installation.html">Installation</a>
</li>
</ul>
<p>Developer Guides</p>
<ul>
<li>
<a href="dev_bean.html">Bean Tags</a>
</li>
<li>
<a href="dev_html.html">HTML Tags</a>
</li>
<li>
<a href="dev_logic.html">Logic Tags</a>
</li>
<li>
<a href="dev_nested.html">Nested Tags</a>
</li>
<li>
<a href="dev_tiles.html">Tiles Tags</a>
</li>
<li>
<a href="dev_util.html">Utilities</a>
</li>
<li>
<a href="dev_validator.html">Validator</a>
</li>
</ul>
<p>Quick Links</p>
<ul>
<li>
<a href="../index.html">Welcome</a>
</li>
<li>
<a href="index.html">User and Developer Guides *</a>
</li>
<li>
<a href="../faqs/index.html">FAQs and HowTos</a>
</li>
</ul>
</div>
<!--end menu-->
<div id="main">
<h2 id="top">Struts Logic Tags</h2>
<div class="indent">
<p>This tag library contains tags that are useful in managing conditional
generation of output text, looping over object collections for
repetitive generation of output text, and application flow management.</p>
<p>For tags that do value comparisons (<code>equal</code>,
<code>greaterEqual</code>, <code>greaterThan</code>, <code>lessEqual</code>,
<code>lessThan</code>, <code>notEqual</code>), the following rules apply:</p>
<ul>
<li>The specified value is examined. If it can be converted successfully
to a <code>double</code> or a <code>long</code>, it is assumed that the
ultimate comparison will be numeric (either floating point or integer).
Otherwise, a String comparison will be performed.</li>
<li>The variable to be compared to is retrieved, based on the selector
attribute(s) (<code>cookie</code>, <code>header</code>,
<code>name</code>, <code>parameter</code>, <code>property</code>)
present on this tag. It will be converted to the appropriate type
for the comparison, as determined above.</li>
<li>If the specified variable or property returns null, it will be
coerced to a zero-length string before the comparison occurs.</li>
<li>The specific comparison for this tag will be performed, and the nested
body content of this tag will be evaluated if the comparison returns
a <code>true</code> result.</li>
</ul>
<p>For tags that do substring matching (<code>match</code>,
<code>notMatch</code>), the following rules apply:</p>
<ul>
<li>The specified variable is retrieved, based on the selector attribute(s)
(<code>cookie</code>, <code>header</code>, <code>name</code>,
<code>parameter</code>, <code>property</code>) present on this tag.
The variable is converted to a String, if necessary.</li>
<li>A request time exception will be thrown if the specified variable
cannot be retrieved, or has a null value.</li>
<li>The specified value is checked for existence as a substring of the
variable, in the position specified by the <code>location</code>
attribute, as follows: at the beginning (if location is set to
<code>start</code>), at the end (if location is set to
<code>end</code>), or anywhere (if location is not specified).</li>
</ul>
<p>Many of the tags in this tag library will throw a
<code>JspException</code> at runtime when they are utilized incorrectly
(such as when you specify an invalid combination of tag attributes). JSP
allows you to declare an "error page" in the <code><%@ page %></code>
directive. If you wish to process the actual exception that caused the
problem, it is passed to the error page as a request attribute under key
<code>org.apache.struts.action.EXCEPTION</code>.</p>
<table class="taglib-summary">
<thead>
<tr>
<th>Tag Name</th>
<th>Description</th>
</tr>
</thead>
<tr class="evenRow">
<td align="center">
<a href="#empty">empty</a>
</td>
<td>
Evaluate the nested body content of this tag if the requested variable is
either null or an empty string.
</td>
</tr>
<tr class="oddRow">
<td align="center">
<a href="#equal">equal</a>
</td>
<td>
Evaluate the nested body content of this tag if the requested
variable is equal to the specified value.
</td>
</tr>
<tr class="evenRow">
<td align="center">
<a href="#forward">forward</a>
</td>
<td>
Forward control to the page specified by the specified ActionForward
entry.
</td>
</tr>
<tr class="oddRow">
<td align="center">
<a href="#greaterEqual">greaterEqual</a>
</td>
<td>
Evaluate the nested body content of this tag if the requested
variable is greater than or equal to the specified value.
</td>
</tr>
<tr class="evenRow">
<td align="center">
<a href="#greaterThan">greaterThan</a>
</td>
<td>
Evaluate the nested body content of this tag if the requested
variable is greater than the specified value.
</td>
</tr>
<tr class="oddRow">
<td align="center">
<a href="#iterate">iterate</a>
</td>
<td>
Repeat the nested body content of this tag over a specified collection.
</td>
</tr>
<tr class="evenRow">
<td align="center">
<a href="#lessEqual">lessEqual</a>
</td>
<td>
Evaluate the nested body content of this tag if the requested
variable is less than or equal to the specified value.
</td>
</tr>
<tr class="oddRow">
<td align="center">
<a href="#lessThan">lessThan</a>
</td>
<td>
Evaluate the nested body content of this tag if the requested
variable is less than the specified value.
</td>
</tr>
<tr class="evenRow">
<td align="center">
<a href="#match">match</a>
</td>
<td>
Evaluate the nested body content of this tag if the specified value
is an appropriate substring of the requested variable.
</td>
</tr>
<tr class="oddRow">
<td align="center">
<a href="#messagesNotPresent">messagesNotPresent</a>
</td>
<td>
Generate the nested body content of this tag if the specified
message is not present in this request.
</td>
</tr>
<tr class="evenRow">
<td align="center">
<a href="#messagesPresent">messagesPresent</a>
</td>
<td>
Generate the nested body content of this tag if the specified
message is present in this request.
</td>
</tr>
<tr class="oddRow">
<td align="center">
<a href="#notEmpty">notEmpty</a>
</td>
<td>
Evaluate the nested body content of this tag if the requested variable is
neither null, nor an empty string, nor an empty java.util.Collection
(tested by the .isEmpty() method on the java.util.Collection interface).
</td>
</tr>
<tr class="evenRow">
<td align="center">
<a href="#notEqual">notEqual</a>
</td>
<td>
Evaluate the nested body content of this tag if the requested
variable is not equal to the specified value.
</td>
</tr>
<tr class="oddRow">
<td align="center">
<a href="#notMatch">notMatch</a>
</td>
<td>
Evaluate the nested body content of this tag if the specified value
is not an appropriate substring of the requested variable.
</td>
</tr>
<tr class="evenRow">
<td align="center">
<a href="#notPresent">notPresent</a>
</td>
<td>
Generate the nested body content of this tag if the specified
value is not present in this request.
</td>
</tr>
<tr class="oddRow">
<td align="center">
<a href="#present">present</a>
</td>
<td>
Generate the nested body content of this tag if the specified
value is present in this request.
</td>
</tr>
<tr class="evenRow">
<td align="center">
<a href="#redirect">redirect</a>
</td>
<td>Render an HTTP Redirect</td>
</tr>
</table>
</div>
<h3 id="empty">
<strong>empty</strong> -
Evaluate the nested body content of this tag if the requested variable is
either null or an empty string.
</h3>
<div class="indent">
<p>This tag evaluates its nested body content only if the specified value
is either absent (i.e. <code>null</code>), an empty string (i.e. a
<code>java.lang.String</code> with a length of zero), or an empty
<code>java.util.Collection</code> or <code>java.util.Map</code> (tested by
the .isEmpty() method on the respective interface).</p>
<p>
<strong>JSTL</strong>: The equivalent JSTL tag is <c:if> using the
<code>empty</code> operator. For example,
<br />
<code>
<c:if test="${empty sessionScope.myBean.myProperty}">
do something
</c:if>
</code>
</p>
<p>Since: Struts 1.1</p>
<table class="tag-attributes">
<thead>
<tr>
<th class="attribute">Attribute Name</th>
<th>Description</th>
</tr>
</thead>
<tr class="evenRow">
<td align="center">name</td>
<td>
<p>The variable to be compared is the JSP bean specified by this
attribute, if <code>property</code> is not specified, or the value
of the specified property of this bean, if <code>property</code>
is specified.</p>
[RT Expr]
</td>
</tr>
<tr class="oddRow">
<td align="center">property</td>
<td>
<p>The variable to be compared is the property (of the bean specified
by the <code>name</code> attribute) specified by this attribute.
The property reference can be simple, nested, and/or indexed.</p>
[RT Expr]
</td>
</tr>
<tr class="evenRow">
<td align="center">scope</td>
<td>
<p>The bean scope within which to search for the bean named by the
<code>name</code> property, or "any scope" if not specified.</p>
[RT Expr]
</td>
</tr>
</table>
</div>
<p>
<a href="#top">Back to top</a>
</p>
<h3 id="equal">
<strong>equal</strong> -
Evaluate the nested body content of this tag if the requested
variable is equal to the specified value.
</h3>
<div class="indent">
<p>Compares the variable specified by one of the selector attributes
against the specified constant value. The nested body content of this
tag is evaluated if the variable and value are <strong>equal</strong>.
</p>
<table class="tag-attributes">
<thead>
<tr>
<th class="attribute">Attribute Name</th>
<th>Description</th>
</tr>
</thead>
<tr class="evenRow">
<td align="center">cookie</td>
<td>
<p>The variable to be compared is the value of the cookie whose
name is specified by this attribute.</p>
[RT Expr]
</td>
</tr>
<tr class="oddRow">
<td align="center">header</td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -