<%
  Vector colorCollection=new Vector();
  colorCollection.add(new org.apache.struts.util.LabelValueBean("显示内容1","值1"));
  colorCollection.add(new org.apache.struts.util.LabelValueBean("显示内容2","值2"));
  pageContext.setAttribute("colorCollection",colorCollection);
%><html:select property="colors" multiple="true">
    <html:options collection="colorCollection" property="value" labelProperty="label"/>
</html:select>

解决方案 »

  1.   

    我的问题是这样的~!
    显示页面
    ------------------------------------------
    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
    <jsp:useBean scope="page" id="Test" class="com.hdtq.main.Testbean"/>
    <jsp:getProperty name="Test" property="search"/>
    ....
        <html:select property="username">
         <html:option value="">--</html:option>
         <html:options  collection="Test" property="provinceid" labelProperty="provincename"/>
        </html:select>
    .....
    ---------------------------------------
    Testbean.java
    --------------------------------------
    public class Testbean { public Collection getSearch(){
    DBCPool dbc= new DBCPool();
    Connection conn=dbc.getConnection("school_1");
    Statement stmt=null;
    Collection mylist1=new ArrayList();
    if(conn!=null){
    try{
    stmt=conn.createStatement();
    }catch(SQLException err){
    System.out.println(err.getMessage());

    }
    }
    ResultSet rs=null;
    try{
    rs=stmt.executeQuery("select provinceID,province from province");
    Test test;
    while(rs.next()){
    test=new Test();
    test.setProvinceid(rs.getString("provinceID"));
    test.setProvincename(rs.getString("province"));
    mylist1.add(test);
    }

    }catch(Exception er){
    System.out.println(er.getMessage());
    }
    try{
    stmt.close();
    conn.close();
    }catch(Exception err1){
    System.out.println(err1.getMessage());
    }
    return mylist1;
    }
    }
    ---------------------------------
    报的是这样的错误...........
    Cannot create iterator for com.hdtq.main.Testbean......过来帮帮我吧
      

  2.   

    你的不是把 集合 放在 pageContext中了吗
    如果 要是从bean中读取 应该怎么做?
    我的代码 有什么问题?
      

  3.   

    集合放在哪是无所谓的
    while(rs.next()){
    org.apache.struts.util.LabelValueBean test=new org.apache.struts.util.LabelValueBean(rs.getString("province"),rs.getString("provinceID")));
    mylist1.add(test);
    }
    然后把集合放到页面容器里,如request,session,pageContext等等页面使用
    <html:options collection="colorCollection" property="value" labelProperty="label"/>
      

  4.   

    lip009(深蓝忧郁) 谢谢
     我试试
    问题不段出现.唉
      

  5.   

    to lip009(深蓝忧郁) :
    好使了,我其实想要做个 级联菜单的(省,市,县),用ajax实现下拉菜单中内容的变换,
    你那有 struts+ajax的级联菜单吗
      

  6.   

    to: zhaochunhui(没有烟抽的日子) ( ) 信誉:100    Blog 我的Blog里有篇级联下拉列表的几种做法总结,AJAX的只有简单代码...你只需要把下拉改成Struts的就可以