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

📄 package-summary.html

📁 struts api,学习使用struts必备的文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
     <li>parameter - the name of the request parameter to compare to <i>value</i>

      <ul>
         <li>example:
          <pre>&lt;logic:<i>someComparisonTag</i> value="" parameter="username"&gt;<br>  Error: a username must be specified<br>&lt;/logic:<i>someComparisonTag</i>&gt;<br></pre>
         </li>

      </ul>
     </li>
     <li>property - the variable to be compared with <i>value</i> is the
property       (of the bean specified by the name attribute) specified by
this attribute.       The property reference can be simple, nested, and/or
indexed. <i>property</i>       is used in conjunction with <i>name</i> to
specify a property in the bean       specified by <i>name</i>. For the type
of syntax used for property, see       the users guide on the Bean Tags.</li>
     <li>scope - the bean scope within which to search for the bean named
by the       name property, or "any scope" if not specified. Possible values
are "page",       "request", "session", "application", or "any       scope"
    </li>

  </ul>

  <p><b>Substring Matching</b> (match, notMatch)</p>

  <p>The substring matching tags take all the same arguments as the value
comparison     tags. You compare the String specified by <i>value</i> to
any of the comparison     values you give it, specified by <i>cookie</i>,
  <i>header</i>, <i>parameter</i>,     <i>property</i> or <i>name.</i> Note
that in the examples, <i>matchTag</i>     corresponds either the <i>match
  </i>or <i>notMatch</i> tag. Matching tags     also have an additional <i>
location</i> attribute added:</p>

  <ul>
     <li>location - has two possible values, "start" and "end".       If
"start", the substring is attempted to be matched at the beginning
of the String, if "end", then the substring is attempted to be       matched
to the end of the String
      <ul>
         <li>example:
          <pre>&lt;logic:<i>matchTag</i> parameter="action" value="processLogin" location="start"&gt;<br>  Processing Login....<br>&lt;/logic:<i>matchTag</i>&gt;<br><br>In this example, a request parameter "action" was compared to see if<br>its value started with the String "processLogin". In this case,<br><i>matchTag</i> would have to be &lt;logic:match&gt;.<br></pre>
         </li>

      </ul>
     </li>

  </ul>

  <p><b>Presentation Location</b> (forward, redirect)</p>

  <p>The <i>redirect</i> tag is resposible for sending a re-direct to the
client's     browser, complete with URL-rewriting if it's supported by the
container. Its     attributes are consistent with the Struts HTML <a href="../../../../../../userGuide/struts-html.html#link"><code>
link</code></a>
     tag. The base URL is calculated based on which of the following attributes
    you specify (you must specify exactly one of them):</p>

  <ul>
     <li> forward - Use the value of this attribute as the name of a global
ActionForward       to be looked up, and use the context-relative URI found
there. </li>
     <li>href - Use the value of this attribute unchanged. </li>
     <li>page - Use the value of this attribute as a context-relative URI,
and       generate a server-relative URI by including the context path. </li>

  </ul>

  <p>The <i>forward</i> tag is responsible for either redirecting or forwarding
    to a specified global action forward. To define a global ActionForward,
see     The <a href="../../../../../../userGuide/building_controller.html#config">
Action     Mappings Configuration File</a>
. You can specify whether the forward re-directs     or forwards when executed
in the config file. The forward tag has one attribute:</p>

  <ul>
     <li>name - The logical name of the ActionForward to use</li>

  </ul>

  <p><b>Collection Utilities</b> (iterate)</p>

  <p>The <i>iterate</i> tag is responsible for executing its body content
once     for every element inside of the specified Collection. There is one
required     attribute:</p>

  <ul>
     <li>id - The name of a page scope JSP bean that will contain the current
element       of the collection on each iteration</li>

  </ul>

  <p>The other attributes allow for more flexibility on which Collection
to iterate     and how to do it:</p>

  <ul>
     <li>collection - a runtime expression that evaluates to a Collection
to be       iterated
      <ul>
         <li>example:
          <pre>&lt;%<br>  java.util.Vector vector = new java.util.Vector();<br>  vector.add(new Integer(12));<br>  vector.add(new Integer(5));<br> %&gt;<br></pre>
         </li>

      </ul>
     </li>

  </ul>

  <blockquote>
    <blockquote>
      <pre>&lt;logic:iterate id="myCollectionElement" collection="&lt;%= vector %&gt;"&gt;<br><i> Do something with myCollectionElement</i>
&lt;/logic:iterate&gt;
</pre>
     </blockquote>
   </blockquote>

      <ul>
     <li>length - The maximum number of entries (from the underlying collection)
      to be iterated through on this page. This can be either an integer
that       directly expresses the desired value, or the name of a JSP bean
(in any       scope) of type java.lang.Integer that defines the desired value.
If not       present, there will be no limit on the number of iterations
performed</li>
     <li>name - The name of the JSP bean containing the collection to be
iterated       (if property is not specified), or the JSP bean whose property
getter returns       the collection to be iterated (if property is specified).

          <ul>
         <li>example:
              <pre>&lt;%<br>
    java.util.ArrayList list = new java.util.ArrayList();
    list.add("First");
    list.add("Second");
    list.add("Third");
    list.add("Fourth");
    list.add("Fifth");
    pageContext.setAttribute("list", list, PageContext.PAGE_SCOPE);
%&gt;

&lt;logic:iterate id="myCollectionElement" name="list"&gt;
  <i>Do something with myCollectionElement</i>
&lt;/logic:iterate&gt;</pre>
         </li>

          </ul>
     </li>
     <li>offset - The zero-relative index of the starting point at which
entries       from the underlying collection will be iterated through. This
can be either       an integer that directly expresses the desired value,
or the name of a JSP       bean (in any scope) of type java.lang.Integer
that defines the desired value.       If not present, zero is assumed (meaning
that the collection will be iterated       from the beginning. </li>
     <li>property - Name of the property, of the JSP bean specified by name,
whose       getter returns the collection to be iterated. See the user's
guide for the       bean tag library for the syntax of the property attribute</li>
     <li>scope - The bean scope within which to search for the bean named
by the       name property, or "any scope" if not specified. Possible values
are "page",       "request", "session", "application", or "any       scope"
        </li>
     <li>type - Fully qualified Java class name of the element to be exposed
through       the JSP bean named from the id attribute. If not present, no
type conversions       will be performed. NOTE: The actual elements of the
collection must be assignment-compatible       with this class, or a request
time ClassCastException will occur.
          <ul>
         <li>example:
              <pre>&lt;%    java.util.ArrayList list = new java.util.ArrayList();<br>list.add("First");<br>list.add("Second");<br>list.add("Third");<br>list.add("Fourth");<br>list.add("Fifth");<br>    pageContext.setAttribute("list", list, PageContext.PAGE_SCOPE);<br> %&gt;<br><br>&lt;logic:iterate id="myCollectionElement" name="list" type="java.lang.String"&gt;<br>  <i>Do something with myCollectionElement</i>
&lt;/logic:iterate&gt;</pre>
         </li>

          </ul>
     </li>

      </ul>
 </blockquote>

      <h3>Logic Examples<a name="doc.Examples"></a></h3>

      <blockquote>
        <p><b>Value Comparisons</b></p>

        <blockquote>
          <p><u></u><u></u><u>Logic Equivalence Tags (equal, notEqual, greaterEqual,
      lessEqual, lessThan, greaterThan)</u></p>

          <blockquote>
            <p>You can compare these tags to the "==", "!=" ,"&gt;=",
     "&lt;=", "&lt;", and "&gt;"logic operators         in most languages.
Their usage is fairly straightforward for numbers.         For an example,
we'll create a small "Guess That Number" game         that uses request parameters
from a form input to play. The number will         be hardcoded as "7", because
this is just an example. Note that         this is actually putting application
logic inside of jsp pages, and isn't         the recommended development
method for Struts. It's just an easy way to         show how these tags are
used:</p>

            <p>The first step is to develop the form that will call on the
processing         jsp page. This form will use the "GET" method so that
you can         see the request parameter in the URL. The POST method can
also be used         with no problem or changes.</p>

            <p>[numberGuess.jsp]</p>

            <pre>&lt;form action="numberProcess.jsp" method="GET"&gt;<br>Please Enter a Number From 1-10: &lt;input type="text" name="number" /&gt;&lt;br /&gt;<br>  &lt;center&gt;<br>    &lt;input type="submit" name="Guess Number" /&gt;<br>  &lt;/center&gt;<br>&lt;/form&gt;<br></pre>
       The next step is to create the processing page. It uses the struts-logic
      taglib. For information on how to set this tag library up in your application
      to use, see <a href="../../../../../../userGuide/configuration.html#dd_config">
The       Web Application Deployment Descriptor</a>

            <p>[numberProcess.jsp]</p>

            <pre>&lt;%@ page language="java" %&gt;<br>&lt;%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %&gt;<br></pre>

            <pre>&lt;!-- Is the number guess right? --&gt;<br>&lt;logic:equal parameter="number" value="7"&gt;<br>  You guessed right! You win a high speed blender!<br>&lt;/logic:equal&gt;<br></pre>

            <pre>&lt;!-- If the number guessed was wrong --&gt;<br>&lt;logic:notEqual parameter="number" value="7"&gt;<br>  &lt;!-- Less Than --&gt;<br>  &lt;logic:lessThan parameter="number" value="7"&gt;<br>         A little higher...<br>  &lt;/logic:lessThan&gt;<br>  &lt;!-- Greater Than --&gt;<br>  &lt;logic:greaterThan parameter="number" value="7"&gt;<br>         A little lower...<br>  &lt;/logic:greaterThan&gt;<br>&lt;/logic:notEqual&gt;<br></pre>

            <p>Basically, the numberProcess.jsp page uses the equal tag to
check if         the guess is 7, and if so, prints out a congratulatory message.
If the         number isn't equal, specified by the use of the &lt;logic:notEqual&gt;
        tag, it uses the greaterThan and lessThan tags to check if the number
        is higher or lower than 7, and prints out a hint. As said before,
this         is a horribly designed small application, with no validity checks
on the         number input, but shows the basic usage of the logic equal
tags</p>

            <p>For String comparisons, the equal tags use the java.lang.String.compareTo()
        method. See the javadocs on the compareTo() method for more information,
        located <a href="http://www.javasoft.com/products/jdk/1.2/docs/api/java/lang/String.html#compareTo%28java.lang.Object%29">
here</a>
.</p>
     </blockquote>

            <p><u>Match and Present Tags (match, notMatch, present, notPresent)</u></p>

            <blockquote>
              <p>You use the match tags in conjunction with the present tags
in order         to do substring matches. For an example using this we'll
use headers,         specifically the "Referer" header. The HTTP referer
header gives         the URL of the document that refers to the requested
URL. We'll use this         to check if the user is coming from a link specified
by a <a href="http://www.google.com">Google</a>
         search, and offer a personalized greeting, frightening users that
find         our site through the search engine with our amazing intimate
knowledge         of their browsing habits:</p>

              <p>[sneaky.jsp]</p>

              <pre>&lt;%@ page language="java" %&gt;<br>&lt;%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %&gt;<br><br><br>&lt;!-- Check to see if the "Referer" header is present --&gt;<br>&lt;logic:present header="Referer"&gt;<br>  &lt;logic:match header="Referer" value="google.com"&gt;<br>    I see you found our site through Google... interesting.<br>  &lt;/logic:match&gt;<br>  &lt;logic:notMatch header="Referer" value="google.com"&gt;<br>    Welcome to the site, we're secretly logging what site you came from,<br>    because we're shady...<br>  &lt;/logic:notMatch&gt;<br>&lt;/logic:present&gt;<br><br>&lt;!-- If the header is not present --&gt;<br>&lt;logic:notPresent header="Referer"&gt;<br>  Hi, welcome to our site.  Please fill out our<br>  &lt;a href="nonExistantForm.jsp"&gt;Form&lt;/a&gt; and<br>  tell us where you're coming from.<br>&lt;/logic:notPresent&gt;</pre>

              <p>Note: Another interesting usage of these tags and headers
would be to         use the "User-Agent" header to display browser-specific
javascript.</p>
     </blockquote>
   </blockquote>

              <p><b>Collection Utilities (iterate)</b></p>

              <blockquote>
                <p>For an example of using the &lt;logic:iterate&gt; tag,
we'll use one of       the previous examples given, in it's entirety. This
example uses the &lt;bean:write&gt;       tag from the Bean Tag Library,
see the User's Guide on the bean tag library       for more information on
it's usage:</p>

                <p>[iterate.jsp]</p>

                <pre>&lt;%@ page language="java" %&gt;<br>&lt;%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %&gt;<br>&lt;%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %&gt;<br></pre>

                <pre>&lt;%<br>java.util.ArrayList list = new java.util.ArrayList();<br>  list.add("First");<br>  list.add("Second");<br>  list.add("Third");<br>  list.add("Fourth");<br>  list.add("Fifth");<br>  pageContext.setAttribute("list", list, PageContext.PAGE_SCOPE);<br>%&gt;<br><br>&lt;logic:iterate id="myCollectionElement" name="list"&gt;<br>  Element Value: &lt;bean:write name="myCollectionElement" /&gt;&lt;br /&gt;<br>&lt;/logic:iterate&gt;</pre>
 </blockquote>
 </blockquote>
<P>
<HR>

<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-use.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/html/package-summary.html"><B>PREV PACKAGE</B></A>&nbsp;
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/nested/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  <A HREF="../../../../../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
&nbsp;<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->

<HR>
Copyright 

⌨️ 快捷键说明

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