??xml version="1.0" encoding="utf-8" standalone="yes"?>99精品久久免费看蜜臀剧情介绍,一区二区欧美在线,精品美女视频http://www.aygfsteel.com/yunye/category/30266.html ... 阛_明媚的早上,早河边的草坪上搭建我的草?... ........单单........ .............却很实在.........zh-cnFri, 21 Mar 2008 18:20:12 GMTFri, 21 Mar 2008 18:20:12 GMT60标签logic:iteratehttp://www.aygfsteel.com/yunye/articles/187830.html云野云野Fri, 21 Mar 2008 17:00:00 GMThttp://www.aygfsteel.com/yunye/articles/187830.htmlhttp://www.aygfsteel.com/yunye/comments/187830.htmlhttp://www.aygfsteel.com/yunye/articles/187830.html#Feedback0http://www.aygfsteel.com/yunye/comments/commentRss/187830.htmlhttp://www.aygfsteel.com/yunye/services/trackbacks/187830.html
1?java对象的数l?

2?ArrayList、Vector、HashMap{?

  具体用法请参考struts文档Q这里不作详l介l? 

现在定义一个classQUser.java 把它~译成User.class

package example;

import java.io.Serializable;
public final class User implements Serializable {
private String name = null;
private String password = null;

public String getName () {
  return (this.name);
}

public void setName(String name) {
  this.name = name;
}

public String getPassword () {
  return (this. password);
}

public void setPassword (String password) {
  this. password = password;
}

}

  然后在一个struts webapplication中创Z个jspQ例如iterate.jsp



<%@ page language="java" %>
<%@ page import="example.*"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
java.util.ArrayList list = new java.util.ArrayList();
User usera=new User();
usera.setName("white");
usera.setPassword("abcd");
list.add(usera);
User userb=new User();
userb.setName("mary");
userb.setPassword("hijk");
list.add(userb);
session.setAttribute("list", list);

%>

<html><body><table width="100%">

<logic:iterate id="a" name="list" type=" example.User ">

<tr><td width="50%">

    name: <bean:write name="a" property="name"/>

<td/><td width="50%">

    password: <bean:write name="a" property="password"/>

</td></tr>

</logic:iterate>

</table></body></html>

User.class, iterate.jsp攑ֈ相应的目录,q行iterate.jsp你就可以看到iterate的效果了

iterate标记
id   脚本变量的名Uͼ它保存着集合中当前元素的句柄?
name 代表了你需要叠代的集合Q来自session或者request的属性?
type 是其中的集合cd素的cd

bean的write标记是用来将属性输出的Qname用来匚witerate的idQproperty用来匚w相应cȝ属?img src ="http://www.aygfsteel.com/yunye/aggbug/187830.html" width = "1" height = "1" />

云野 2008-03-22 01:00 发表评论
]]>
logic:iterate(2)http://www.aygfsteel.com/yunye/articles/187828.html云野云野Fri, 21 Mar 2008 16:55:00 GMThttp://www.aygfsteel.com/yunye/articles/187828.htmlhttp://www.aygfsteel.com/yunye/comments/187828.htmlhttp://www.aygfsteel.com/yunye/articles/187828.html#Feedback0http://www.aygfsteel.com/yunye/comments/commentRss/187828.htmlhttp://www.aygfsteel.com/yunye/services/trackbacks/187828.html<logic:iterate> ?strong style="color: black; background-color: #ffff66">Logic 标签库中最复杂的标{,也是用途最q的一个标{,它能够在一个@环中遍历数组、Collection、Enumeration?strong style="color: black; background-color: #a0ffff">Iterator ?Map 中的所有元素?/p>

1. 遍历集合
  <logic:iterate> ?name 属性指定需要进行遍历的集合对象, 它每ơ从集合中检索出一个元? 然后把它攑֜page 范围? q以id 属性指定的字符串来命名q个元素, 例如:
    <%
        Vector animals = new Vector();

        animals.addElement("Dog");
        animals.addElement("Cat");
        animals.addElement("Bird");
        animals.addElement("Chick");

        request.setAttribute("Animals", animals);
    %>
    <logic:iterate id="element" name="Animals">
        <bean:write name="element"/><br>
    </logic:iterate>
    以上代码先定义了一个Vector cd的集合变?Animals, 它存攑֜request 范围? 接下?lt;logic:iterate> 标签在一个@环中遍历Animals 集合(q个集合名就是在标签中的name 属性的?中所有元? 每次索到一个元? 把它命名ؓ"element"(标签id 属性的?, q存攑֜page 范围?
    ?lt;logic:iterate> ? q嵌套了一?lt;bean:write>标签, 它用于输出每个元素的内容. 以上代码的输出内容如?
    Dog
    Cat
    Bird
    Chick    
     length    属性指定需要遍历的元素的数? 如果没有讄length 属?遍历集合中的所有元?
    offset      属性指定开始遍历的起始位置, 默认gؓ "0" , 表示从集合的W一个元素开始遍?
    indexId  属性定义一个代表当前遍历元素序L变量, q个变量被存攑֜ page 范围? 可以被标{主体的
<bean:write> 标签讉K. 例如:

    <logic:iterate 
            id="element"           // 指定输出元素的名 ?<bean:write> 中name 属性一?br />             indexId="index"       // 遍历元素序号的变? q个变量攑֜page 范围?br />             name="Animals"    // request 中的集合? 从中取@环取出元?br />             offset="1"                 // 从集合的W?2 条记录开始取?br />             length="2">             // 取出 2 个元?br />         <bean:write name="index"/>.              // 输出每个元素的序? ?strong style="color: black; background-color: #99ff99">indexId 的属性一?br />         <bean:write name="element"/><br>  // 输出每个元素的内? 与id 的属性一?br />     </logic:iterate>

2. 遍历Map
    <logic:iterate> 标签q可以遍历HashMap 中的元素,

例如:
    <%
        HashMap months = new HashMap();
       
        months.put("Jan","January");
        months.put("Feb","February");
        months.put("Mar","March");
       
        request.setAttribute("month", months);
    %>
    <logic:iterate id="element" indexId="ind" name="months">
        <bean:write name="ind"/>.                                          // 序号
        <bean:write name="element" property="key"/>:      // 键名
        <bean:write name="element" property="value"/>    // 键?br />     </logic:iterate>
    以上代码先定义一个名?months" 的HashMap, 存放在request 范围? 接下来在<logic:iterate> 标签遍历months 对象的每一个元? 每一个元素包含一?key/value . ?lt;logic:iterate> 标签M中包含三?lt;bean:write> 标签, 分别输出每个元素的序受key ?value. 以上代码的输出内容如?
    0.Mar: March
    1.Feb: February
    2.Jan: January
    如果HashMap 中的每个元素?value 是集合对?

则可以采用嵌套的<logic:iterate>标签遍历集合中的所有对? 例如:
    <%
           HashMap h = new HashMap();
           String vegetables[] = {"pepper","cucumber"};
           String fruits[] = {"apple","orange","banana","cherry","watermelon"};
           String flowers[] = {"chrysanthemum","rose"};
           String trees[] = {"willow"};
          
           h.put("Vegetables", vegetables);
           h.put("Fruits",fruits);
           h.put("Flowers",flowers);
           h.put("Trees",trees);
          
           request.setAttribute("catalog",h);
    %>
    <logic:iterate   id="element"              // ?lt;bean:write> 中的name 属性对? 输出内容
                              indexId="ind"              // ?lt;bean:write> 中的name 属性对? 输出序号
                  &nbsp;           name="catelog">      // 指定输出元素的名U?br />         <bean:write name="ind"/>.           // 输出序号
        <bean:write name="element"      // ?lt;logic:iterate>中id 属性对?
  property="key"/>    // 集合中的键名

        <logic:iterate
                id="elementValue"   // ?lt;bean:write> 中的name 属性对?br />                 name="element"      // 指定输出元素的名U?br />                 property="value"       // 集合中的键?br />                 length="3"                  // ? 个元?br />   offset="1">                               // 从第 2 个位|取
     -------<bean:write name="elementValue"/>
 </logic:iterate>

    </logic:iterate>


    以上代码先定义一个名?catelog" 的HashMap , 存放在request 范围?它的每个元素的value 为字W串数组.
    接下来外层的<logic:iterate>标签遍历HashMap 中的所有元? 内层?lt;logic:iterate>标签讉K每个元素的value 属? 遍历value 属性引用的字符串数l中的所有元?

3. 讄被遍历的变量
    可以通过以下方式来设|需要遍历的变量
    (1) 讄name 属? name 属性指定需要遍历的集合或Map, 例如:
        <logic:iterate id="element" name="Animals">
            <bean:write name="element"/>
        </logic:iterate>
    (2) 讄name 属性和property 属? name 属性指定一个JavaBean, property 属性指定JavaBean 的一个属? q个属性ؓ需要遍历的集合或Map, 例如:
        <logic:iterate id="element" indexId="ind" name="catelog">
            <bean:write name="ind"/>
            <bean:write name="element" property="key"/>
            <logic:iterate id="elementValue" name="element" property="value" length="3" offset="1">
                --------<bean:write name="elementValue"/>
            </logic:iterate>
        </logic:iterate>
    (3) 讄collection 属?collection 属性指定一个运行时表达? 表达式的q算l果为需要遍历的集合或Map, 例如:
       
        <logic:iterate id="header" collection"<%=request.getHeaderNames()%>">
            <bean:write name="header"/>
        </logic:iterate>

4. dJavaBean 中的数据
  (1) 在Jsp 面中加入JavaBean ?
        <jsp:useBean id="articleClasses" class="com.GetArticleClasses"/>
      上面q个JavaBean 要求必须存在一个集合数l对象,如Vector,Collection,ArrayList {;在这个JavaBean 的构造函CQ取得数?/p>

库中的数据,q将其存入数l对象中?br />   (2) 使用<logic:iterate> 标签Q取出JavaBean 中存攄数组对象中的数据

        <logic:iterate
                  id="aClasses"                   //  id   : l检索出的元素所命的?
                  name="articleClasses"   //  name : JavaBean 在页面中所讄的引用ID.
                  property="coll">                 //  coll : JavaBean 中的集合数组属性名U?
            <tr> 
                <td onMouseOver="this.bgColor=''#FFFFFF'onMouseOut="this.bgColor=''''">&nbsp;&nbsp;&nbsp;&nbsp;
             <html:link  page="/articleListAction.do"
                                 paramId="classId" 
                                 paramName="aClasses"
                                 paramProperty="classId">
          <bean:write name="aClasses"       // ?lt;logic:iterate> 标签中的id 属性相对应
                       property="className" />     // 取出JavaBean中, 存放在集合对象中的,对象的className 属性?br />              </html:link>
         </td>
            </tr>
        </logic:iterate>
  (3) 在JavaBean 中的集合对象中存攑֮体对象的语句如下:
        ......
        public class GetArticleClasses
        {
            // 数据集合
            private Collection coll;
   
 &nbsp;          // q回数据集合
            public Collection getColl()
            {
                return coll;
            }
            // 构造函? 取出数据Q存入集合中
            public GetArticleClasses()
            {
                coll = new ArrayList();
                try{
                    // 数据库连?br />                     Connection connection = DBConnection.getConnection();
                    if(connection != null)
                    {
                        Statement statement = connection.createStatement();
                        ResultSet resultset;
                        ArticleClass articleclass;
                        resultset = statement.executeQuery("SELECT * FROM table ORDER BY id");
         &nbsp;              while( resultset.next())
                        {
                            articleclass = new ArticleClass();
                            articleclass.setId(resultset.getInt("id"));
                            articleclass.setClassId(resultset.getString("class"));
                            articleclass.setClassName(resultset.getString("name"));
                           
                            coll.add(articleclass))
                }

                resultset.close();
                connection.close();
            } else {
                coll = null;
            }
        } catch(Exception exception) {
            coll = null;
        }
}
}



云野 2008-03-22 00:55 发表评论
]]>
logic:iteratehttp://www.aygfsteel.com/yunye/articles/187827.html云野云野Fri, 21 Mar 2008 16:43:00 GMThttp://www.aygfsteel.com/yunye/articles/187827.htmlhttp://www.aygfsteel.com/yunye/comments/187827.htmlhttp://www.aygfsteel.com/yunye/articles/187827.html#Feedback0http://www.aygfsteel.com/yunye/comments/commentRss/187827.htmlhttp://www.aygfsteel.com/yunye/services/trackbacks/187827.html<logic:iterate>标记用于在页面中创徏一个@?以此来遍历如数组、Collection、Mapq样的对象。该标记的功能强大,在Struts应用的页面中l常使用到?br /> 1、对数组q行循环遍历
使用<logic:iterate>标记可以用于遍历数组Q以下是一D늤例代码:

<%
String[] testArray={"str1","str2","str3"};
pageContext.setAttribute("test",testArray);
%>
<logic:iterate id="show" name="test">
<bean:write name="show"/>
</logic:iterate>

在上面的代码中,首先定义了一个字W串数组Qƈ为其初始化。接着Q将该数l存入pageContext对象中,命名为test1。然后?lt;logic:iterate>标记的name属性指定了该数l,q用id来引用它Q同时?lt;bean:write>标记来将其显C出来。其l果为:
str1
str2
str3


另外Q还可以通过length属性来指定输出元素的个数。如下面的代码:
<logic:iterate id="show" name="test" length="2" offset="1">
<bean:write name="show"/>
</logic:iterate>

其中length属性指定了输出元素的个敎ͼoffset属性指定了从第几个元素开始输出,如此处ؓ1Q则表示从第二个元素开始输出。所以该代码的运行结果应当输出:
str2
str3


另外Q该标记q有一个indexId属性,它指定一个变量存攑ֽ前集合中正被讉K的元素的序号Q如Q?br />

<logic:iterate id="show" name="test" length="2" offset="1" indexId="number">
<bean:write name="number"/>:<bean:write name="show"/>
</logic:iterate>

其显C结果ؓQ?br /> 1:str2
2:str3

2、对HashMapq行循环遍历

<%
HashMap countries=new HashMap();
countries.put("country1","中国");
countries.put("country2","国");
countries.put("country3","英国");
countries.put("country4","法国");
countries.put("country5","德国");
pageContext.setAttribute("countries",countries);
%>
<logic:iterate id="country" name="countries">
<bean:write name="country" property="key"/>:
<bean:write name="country" property="value"/>
</logic:iterate>


在bean:write中通过property的key和value分别获得HaspMap对象的键和倹{其昄l果为:
country5:德国
country3:英国
country2:国
country4:法国
country1:中国

q果可看出Q它q未按添加的序其昄出来。这是因为HaspMap是无序存攄?br />
3、嵌套遍?/strong>

<%
String[] colors={"red","green","blue"};
String[] countries1={"中国","国","法国"};
String[] persons={"乔丹","布什","克林?};
ArrayList list2=new ArrayList();
list2.add(colors);
list2.add(countries1);
list2.add(persons);
pageContext.setAttribute("list2",list2);
%>
<logic:iterate id="first" name="list2" indexId="numberfirst">
<bean:write name="numberfirst"/>
<logic:iterate id="second" name="first">
<bean:write name="second"/>
</logic:iterate>
<br>
</logic:iterate>


q行效果Q?br /> 0 red green blue
1 中国 国 法国
2 乔丹 布什 克林?/span>
<logic:iterate id="it" name="list" length="2">
<bean write name="it"/><br/>
</logic:iterate>

list 是你要遍例的对象 it是list里面的元素的cd ,q有个offset属性,是用来表Cv始位|的Q比如,offsetQ?#8220;1”从第二位开始遍历出|offsetQ?#8220;0”是默认?/p>

云野 2008-03-22 00:43 发表评论
]]>
վ֩ģ壺 | | Ȫ| żҽ| Ӽ| | | | | ɽ| | Ӧ| ȫ| ƽ| | | ˳| | | | | | | ˺| ˮ| ͬ| ͬ| | Դ| ƽȪ| | ɽ| | | | | Ԫ| | | ľ| Դ|