<html:select  property="Select" size="1" value="Single 2">
<html:option value="Single 0">0</html:option>
<html:option value="Single 1">1</html:option>
<html:option value="Single 2">2</html:option>
   </html:select>

解决方案 »

  1.   

    private String[] select= { "single0", "single2"};    public String[] getSelect() {
            return (this.select);
        }    public void setSelect(String sSelect[]) {
            this.select = select;
        }
      

  2.   

    比如:
    <html:select property="idKind"  multiple="true"  >
       <html:options collection="idKinds" property="value" labelProperty="label"  />
    </html:select>
    现在问题是有要先把一些idKinds设置成已选状态,该怎么办
      

  3.   

    一样:
    <%
    String sQueryValue=查询数据;
    %>
    <html:select property="idKind"  multiple="true"  value="<%=sQueryValue%>">
       <html:options collection="idKinds" property="value" labelProperty="label"  />
    </html:select>
      

  4.   

    例子---来自struts官方网站:
    页面:
          <html:select property="beanCollectionSelect" size="10" multiple="true">
            <html:optionsCollection name="testbean" property="beanCollection"/>
          </html:select>
    ActionForm:(TestBean)
    /**
         * A multiple-String SELECT element using a bean collection.
         */
        private String[] beanCollectionSelect = { "Value 1", "Value 3",
                                                  "Value 5" };    public String[] getBeanCollectionSelect() {
            return (this.beanCollectionSelect);
        }    public void setBeanCollectionSelect(String beanCollectionSelect[]) {
            this.beanCollectionSelect = beanCollectionSelect;
        }
      

  5.   

    to  Tongates(文文) :struts官方网站的例子是读取多重参数的例子
    to  3332221119(飘) :我不相信你那些写jsp可以编译通过,而且查询数据的组织格式是什么?这些东西写到jsp中也好的。
      

  6.   

    我说的是sQueryValue是什么格式呀,应该是一个字符串数组才对呀
    而且,这样用也不专业,应该是把formbean在Action中就设置好,jsp没必要管这些了。
      

  7.   

    哦,struts中的setect标签支持多选了吗
    我只看过struts1.1的源代码,是不支持多选的
      

  8.   

    看一下Struts官方的资料,他对select标签的Value属性作如下解释:
    The value to compare with for ing an option selected.  
    注意,是an option,不是some options,所以,value指出的只能是单个选中,而我上面所说的官方例子,并非是读去多重参数的例子,你可以看struts/example包下面的html-tag的例子,很有帮助的。所以我觉得应该是按例子的样子社指初始多选的。——或许我孤陋寡闻了吧。
      

  9.   

    Tongates(文文) ,那个例子的原文我没有找到,不过从ActionForm类的名字看TestBean是继承ActionForm类的,这个类是用来存放和显示form的数据的,但我不知道对于多重选项可不可以显示。
    还有谁知道呀?郁闷中……
      

  10.   

    呵呵,当然没有问题了,因为那是struts的example阿。
    我给你贴原文吧
      

  11.   

    说错了,是在exercise-taglib目录下的,原文如下
      

  12.   

    <%@ page language="java" import="java.util.*, org.apache.struts.util.*"%>
    <%@ 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" %>
    <html:html>
    <head>
    <title>Test html:select Tag</title>
    <%
      String multipleValues[] =
       { "Multiple 0", "Multiple 1", "Multiple 2", "Multiple 3", "Multiple 4",
         "Multiple 5", "Multiple 6", "Multiple 7", "Multiple 8", "Multiple 9" };
      pageContext.setAttribute("multipleValues", multipleValues);  Vector options = new Vector();
      options.add(new LabelValueBean("Label 0", "Value 0"));
      options.add(new LabelValueBean("Label 1", "Value 1"));
      options.add(new LabelValueBean("Label 2", "Value 2"));
      options.add(new LabelValueBean("Label 3", "Value 3"));
      options.add(new LabelValueBean("Label 4", "Value 4"));
      options.add(new LabelValueBean("Label 5", "Value 5"));
      options.add(new LabelValueBean("Label 6", "Value 6"));
      options.add(new LabelValueBean("Label 7", "Value 7"));
      options.add(new LabelValueBean("Label 8", "Value 8"));
      options.add(new LabelValueBean("Label 9", "Value 9"));
      pageContext.setAttribute("options", options);  String withNulls[] =
       { "String 0", null, "String 2" };
      pageContext.setAttribute("withNulls", withNulls);%>
    </head>
    <body bgcolor="white"><div align="center">
    <h1>Test struts-html Select Tag</h1>
    </div>Whatever changes you make to properties should be reflected when the page
    is redisplayed.  Press "Save" to update, or "Cancel" to return to the
    main menu.<%--
         Ensure that the form bean exists before the form tag is processed. This
         is a simple (if not entirely clean) way of ensuring that the initial
         values assigned during bean instantiation will be available within the
         form, since reset() will not be called when the form bean already exists.     The right way to fix this is to modify this webapp so that it does not
         refer directly to JSP pages, but goes through Action classes, and to
         either modify the TestBean class, adding an initialize() method, or to
         have an Action class set the initial values.
    --%>
    <jsp:useBean id="testbean" scope="session" class="org.apache.struts.webapp.exercise.TestBean"/><html:form action="html-select.do">
    <table border="0" width="100%">  <tr>
        <th align="right">Single Select Allowed:</th>
        <td align="left">
          <html:select property="singleSelect" size="10">
            <html:option value="Single 0">Single 0</html:option>
            <html:option value="Single 1">Single 1</html:option>
            <html:option value="Single 2">Single 2</html:option>
            <html:option value="Single 3">Single 3</html:option>
            <html:option value="Single 4">Single 4</html:option>
            <html:option value="Single 5">Single 5</html:option>
            <html:option value="Single 6">Single 6</html:option>
            <html:option value="Single 7">Single 7</html:option>
            <html:option value="Single 8">Single 8</html:option>
            <html:option value="Single 9">Single 9</html:option>
          </html:select>
        </td>
      </tr>  <tr>
        <th align="right">Multiple Select Allowed:</th>
        <td align="left">
          <html:select property="multipleSelect" size="10" multiple="true">
            <html:options name="multipleValues" labelName="multipleValues"/>
          </html:select>
        </td>
      </tr>  <tr>
        <th align="right">Multiple Select From A Collection (Using &lt;html:options&gt;):</th>
        <td align="left">
          <html:select property="collectionSelect" size="10" multiple="true">
            <html:options collection="options" property="value" labelProperty="label"/>
          </html:select>
        </td>
      </tr>  <tr>
        <th align="right">Multiple Select From A Collection (Using &lt;html:optionsCollection&gt;):</th>
        <td align="left">
          <html:select property="beanCollectionSelect" size="10" multiple="true">
            <html:optionsCollection name="testbean" property="beanCollection"/>
          </html:select>
        </td>
      </tr>  <tr>
        <th align="right">Select With Labels From Resources:</th>
        <td align="left">
          <html:select property="resourcesSelect" size="3">
            <html:option value="Resources 0" key="resources0"/>
            <html:option value="Resources 1" key="resources1"/>
            <html:option value="Resources 2" key="resources2"/>
          </html:select>
        </td>
      </tr>  <tr>
        <th align="right">
          Collection with null labels and values:
        </th>
        <td align="left">
          <html:select property="withNulls" size="3">
            <html:options name="withNulls" labelName="withNulls"/>
          </html:select>
        </td>
      </tr>  <tr>
        <td align="right">
          <html:submit>Save</html:submit>
        </td>
        <td align="left">
          <html:reset>Reset</html:reset>
          <html:cancel>Cancel</html:cancel>
        </td>
      </tr></table></html:form>
    </html:html>
      

  13.   

    谢谢大家了,我昨天晚上自己测试了一下,发现是自己看struts的源码不仔细的原因,只要把formbean中的该输入项的属性设置成字符串数组,是可以支持多重选项的。