<%
String users[] =
{ "Bob", "Robert", "Roberto", "Bobby"};
pageContext.setAttribute("users", users);
%>
<html:form action="select&#8722;user.do" method="POST">
<table border="0" width="100%">
<tr>
<td
<html:select property="userList" size="4"
multiple="true">
<html:options name="users"
labelName="users"/>
</html:select>
</td>
</tr>
</table>
<html:submit>Save</html:submit>
<html:form>users[] 换成从数据库中取

解决方案 »

  1.   

    简单说说一下
    一般的传统的标签是这样子的。
    <html: select property="yourchoice" size="4">   
    <html:option value="2">温州地区终端</html:option>
    <html:option value="3">宁波地区终端</html:option>
    <html:option value="4">杭州地区终端</html:option>
    </html:select>这个啊,你可以在 forward这个也叶面之前,在request里面设置yourchoic,如果多选就 设置type="java.lang.String[]"; initial="2 4" ;如果你象这个列表也是动态的,那就用 labelProperty 标签属性
    <html:options collection="queryList" property="yourchoice" labelProperty="yourselectedfromdb"/>
    当然也是在forward这个页面之前的request里设置。
    好久不用struts了,大致就是这样,你试试
      

  2.   

    这个我也知道啊,但是表现出来的时候
    selected="selected" 我希望是4或者2我怎么能够动态的显示啊
    <select name="group_id" size="20">
       <option value="2">温州地区终端</option>
       <option value="3">宁波地区终端</option>
       <option value="4">杭州地区终端</option>
       <option value="1" selected="selected">所有终端</option>
    </select>
      

  3.   

    关键在于设置 property 
      

  4.   

    设置的不是在actionform 里面静态设置
      

  5.   

    楼主,这样做:
    在Action里面,把查到的结果装到一个ArrayList里面
    如:ArrayList cityCollection = new ArrayList();
        cityCollection.add(new LabelValueBean(xxx,yyy));//xxx为label,yyy为value
        …
        request.setAttribute("cityCollection",cityCollection);
        …
    再在jsp里面:
    <html:select…>
    <html:options collection="cityCollection " property="value" labelProperty="label"/>
    </html:select>
    就可以了。当然也可以用<logic:iterate>这个标签。
    <html:select>
    <logic:iterate id="cityCollection " name="option">
       <option value='<bean:write property="value" name="option"/>'><bean:write property="label" name="option"/></option>
    </logic:iterate>
      

  6.   

    不好意思哟~上面写错了
    <logic:iterate id="cityCollection " name="option">
    应为
    <logic:iterate id="cityCollection " id="option">
      

  7.   

    <html:select property="xxxx">
    <html:options collection="cityList" property="id" labelProperty="cityName">
    </html:select>
      

  8.   

    我是自己写了一个select的tag,在显示前只要在request.setAttribute("group_id",value);
    就可以动态显示哪个被选中了。
      

  9.   

    leowu(leo) 
    能够给我个提示吗