如果我把代码1改成vt.add(rs.getString(1));
vt.add(rs.getString(2));
vt.add(rs.getString(3));
错误就变了,成javax.servlet.jsp.JspException: No collection found

解决方案 »

  1.   

    呵呵,没有用过vector,学习。
    为什么               <logic:iterate scope="request" name="result" id="vt">
                      
                      <tr>                    
                         <logic:iterate name="vt" id="lname">
    要把id 和下一个name起一样的名字呢?不明白。
      

  2.   

    ResultSetMetaData tm = rs.getMetaData();//rs为结果集,查询Northwind数据库语句为select * from Orders where EmployeeID=?
    int lieshu = tm.getColumnCount();//获取结果列数
    //rs的数据付给al
               Vector vt = new Vector(); (修改)
    while(rs.next())
    { /*********代码1 begin*******/
             for(int i=1;i<lieshu+1;i++)
             {
             vt.add(rs.getString(i));
              }
             /*********代码1 end*******/

            al.add(vt);

    }
                 request.setAttribute("result",al);
    数据表中字段是不是有不同. rs.getInt()
      

  3.   

    既然是嵌套,建议采用<nested:iterate>标签,例子中<logic:iterate>中id的域定义不知是否支持嵌套。
    另外,一般像这类需求不建议用嵌套的方式解决,当顺序调整或字段增减时会较难维护。你可以定一个vo类,在代码1处将一行数据写入一个vo对象,然后返回一个vo的list,页面处理也更可读方便。
      

  4.   

    集合里装集合啊?这个好像得用HashMap装集合吧?直接ArrayList里面放Vector肯定报错的啊!
      

  5.   

    iterator支持嵌套, 你的写法也没啥问题
    用 List 套 List 试试看
      

  6.   

    进行循环遍历的Logic标签
    <logic:iterate>是Logic标签库中最复杂的标签,它能够在一个循环中遍历数组,Collection,Enumeration,Iterator或Map中的所有元素。
     1、遍历集合
        <logic:iterate>的name属性指定需要进行遍历的集合对象,它每次从集合中检索出一个元素,然后把它存放在page范围内,并以id属性指定的字符串来命名这个元素,例如:
     <%
     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><p>
    以上代码的输出内容为:
          Dog 
          Cat
          Bird
          Chick
    length属性指定需要遍历的元素的数目,如果没有设置length属性,就遍历集合中的所有元素,offset属性指定开始遍历的起始位置,默认值“0”,表示从一个集合的第一个元素开始遍历,indexId属性定义一个代表当前被遍历元素序号的变量,这个变量被存放在page范围内,可以被标签主体的<bean:write>标签访问,例如:
      <logic:iterate id="element" indexId="index" name="Animals" offset="1" length="2">
       <bean:write name="index"/>.<bean:write name="element"/><BR>
      </logic:iterate><p>
      以上标签的length属性为2,表示只需要遍历Animals集合中的两个元素,offset为1,表示从第二个元素开始遍历,输出内容为:
           1、Cat
           2、Bird
    2、遍历Map
       <logic:iterate>标签还可以遍历HashMap中的元素,例如:
       <%
    HashMap months = new HashMap();
    months.put("Jan.", "January");
    months.put("Feb.", "February");
    months.put("Mar.", "March");
    request.setAttribute("months", months);
    %>
    <%--
    The following section shows iterate.
    --%>
    <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><P>
      标签遍历months对象的每一个元素,每一个元素都包含一对key/value,以上代码输出:
       0、Mar:March
       1、Feb:Feberuary
       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);
    %>
    <%--
    The following section shows iterate.
    --%><logic:iterate id="element" indexId="ind" name="catalog">
      <bean:write name="ind"/>. <bean:write name="element" property="key"/><BR>
      <logic:iterate id="elementValue" name="element" property="value" length="3" offset="1">
          -----<bean:write name="elementValue"/><BR>
      </logic:iterate>
    </logic:iterate><P>
    以上代码下定义了一个名为'catalog'的HashMap,存放在request范围,它的每个元素的value为字符串数组,接下来外层的标签遍历HashMap中的所有元素,内层的标签访问每个元素的value属性,遍历value属性引用的字符串数组中的所有元素,输出内容为:
        0. Vegetables
        ----cucumber
        1、Flowers
        ----rose
        2.Fruits
        ----orange
        ----banana
        ----cherry
        3.Trees
    3、设置被遍历的变量
    可以通过以下方式来设置需要遍历的变量。
    a、设置name属性,name属性指定需要遍历的集合或Map,例如:
      <logic:iterate id="element" name="Animals">
       <bean:write name="element"/><BR>
    </logic:iterate><p>
    b、设置name属性和property属性,name属性指定一个JavaBean,property属性指定JavaBean的一个属性,这个属性为需要遍历的集合或Map,例如:
    <logic:iterate id="element" indexId="ind" name="catalog">
      <bean:write name="ind"/>. <bean:write name="element" property="key"/><BR>
      <logic:iterate id="elementValue" name="element" property="value" length="3" offset="1">
          -----<bean:write name="elementValue"/><BR>
      </logic:iterate>
    </logic:iterate><P>
    c、设置collection属性,collection属性指定一个运行时表达式,表达式的运算结果为需要遍历的集合或Map,例如:
      <logic:iterate id="header" collection="<%= request.getHeaderNames() %>">
       <bean:write name="header"/><BR>
    </logic:iterate>
     进行请求转发或重定向的Logic标签
    1、<logic:forward>标签该标签用于请求转发,它的name属性指定转发目标,於Struts配置文件中的<global-forwards>元素中的子元素<forward>匹配,例如,在配置文件中:      <global-forwards>
          <forward   name="index"   path="/index.jsp"/>
          </global-forwards>
    这样jsp中通过<logic:forward>标签把请求转发给name属性为“index”的全局转发目标:
    <logic:forward name ="index"/>
    这样当浏览器访问标签所在jsp时,标签把请求转发给index.jsp,因此浏览器看到的是index.jsp2、<logic:redirect>标签
    该标签用于重定向,它的forward,href和page属性指定重定向目标,这几个属性的用法和<html:link>的forward,href,page属性类似,例如:
      <logic:redirect href="http://www.apache.org"/>
    这样浏览器访问标签所在jsp时,标签把请求重定向到href属性内容,因此浏览器看到的是
      

  7.   

    no vector, just ArrayList
      

  8.   

    不多说
    <bean:write name="lname"/>
    改为
    <c:out value="${lname}">记住bean:write中的name是formbean的name
    所以会出现这样的异常javax.servlet.jsp.JspException: Cannot find bean lname in any scope