我用的struts架构
jsp页面中:
<html:select property="interesting"  multiple="true">
<html:option value="htmlselect.sing">Sing</html:option>
<html:option value="htmlselect.print">Print</html:option>
<html:option value="htmlselect.film">Film</html:option>
<html:option value="htmlselect.computerGame">Computer Game</html:option>
<html:option value="htmlselect.other">Other</html:option>
</html:select>
可以多选,对应的form中,我定义了一个与之对应的数组,可以自动获得值,问题是
自动获得的是我选中的value值,如:htmlselect.print,而我想要的是显示的文本值,如何得到呢。不能把value和显示文本写成一样的。
高手指点一下,分不多了,多谢。

解决方案 »

  1.   

    同意楼上的,只能取value,把文本值写到资源文件,通过key来取得
      

  2.   

    你把value值和key对应,这样就可以了,或者索性value和文本一样呵呵
      

  3.   

    首先用了struts的tag问题变得很简单了<html:select size="1" styleClass="scrolltext"  name="FolderManagerForm" property="avaiableFolder" style="width=100%" onchange="parentChange();return false;">
          <html:options name="FolderManagerForm" labelProperty="dropFolderNameList" property="dropFolderList" /> 
    </html:select>这个就是标准的struts的实现方式
    <html:select 中:
    name="FolderManagerForm"   你的form的名字
    property="avaiableFolder"   你改为“interesting”<html:options 中:
    name="FolderManagerForm"  你的form的名字
    labelProperty="dropFolderNameList" 
    property="dropFolderList" property,labelProperty 分别对应你下拉列表的List值。property 在form中是一个ArrayList。用来表示code
    labelProperty 在form中是一个ArrayList。用来表示名称
    比如问题中
    value="htmlselect.sing">Sing</html:option>
    <html:option value="htmlselect.print">Print</html:option>
    <html:option value="htmlselect.film">Film</html:option>
    <html:option value="htmlselect.computerGame">Computer Game</html:option>
    <html:option value="htmlselect.other">Other</html:option>可以把Sing,Print。。 放到一个ArrayList中,然后通过 labelProperty  表示出来
      

  4.   

    luyang1016(闭月羞花猫)
    -------------
    有点糊涂
      

  5.   

    你自己上网找找,这个是标准的<html:select>的写法
      

  6.   

    首先你要定义个form。
    form里面定义2个list, 分别用来表示codeList和nameList,
    再定义个String 来表示所选择的值selectItem然后在java程序里。
    codeList.add("1");
    codeList.add("2");
    codeList.add("3");
    codeList.add("4");
    codeList.add("5");nameList.add("Sing")
    nameList.add("Print")
    ...
    ...selectItem = “随便一个初始值”然后就OK了
      

  7.   

    ArrayList arrayList = new ArrayList();arrayList.add(new LabelValueBean("1001","name1"));
    arrayList.add(new LabelValueBean("1002","name2"));
    arrayList.add(new LabelValueBean("1003","name3"));request.setAttribute("list",arrayList);------------------
    在JSP页面如下
    <html:select property="username">
    <html:options collection="list" property="id" labelProperty="name" />
    </html:select/>这样可以实现,不过我是直接转到jsp页面,这句request.setAttribute("list",arrayList);
    我应当放哪合适。不能放到JSP中
      

  8.   

    luyang1016(闭月羞花猫)
    --------------
    感觉有问题啊,我是想要得到显示的值,并不是如何显示的问题啊。呵呵
      

  9.   

    <body>
    <form>
    <select name="select1">
    <option value="v1">l1</option>
    <option value="v2">l2</option>
    </select>
    <input type="hidden" name="hide1">
    <input type="submit" onclick="document.all['hide1'].value=document.all['select1'].options[document.all['select1'].selectedIndex].text;">
    </form>
    </body>
      

  10.   

    我觉的可以变通一下 改为
    jsp页面中:
    <html:select property="interesting"  multiple="true">
    <html:option value="htmlselect.sing$Sing">Sing</html:option>
    <html:option value="htmlselect.print$Print">Print</html:option>
    <html:option value="htmlselect.film$Film">Film</html:option>
    <html:option value="htmlselect.computerGame$Computer Game">Computer Game</html:option>
    <html:option value="htmlselect.other$Other">Other</html:option>
    </html:select>
    然后根据传进的值是否indexOf(数组[i]) != -1 ,那么split('$')后的数组[1]就是得到的值了
      

  11.   

    多谢各位。
    我对js不熟悉,现在把select用options了,全部放到一个properties里面,value和text设定成一样的,不搞那末复杂了。也看不出什莫优势阿。
    value和text不一样真的有优势吗
      

  12.   

    ArrayList arrayList = new ArrayList();arrayList.add(new LabelValueBean("1001","name1"));
    arrayList.add(new LabelValueBean("1002","name2"));
    arrayList.add(new LabelValueBean("1003","name3"));request.setAttribute("list",arrayList);
    可以在Action里实现.
    <html:select property="username">
    <html:options collection="list" property="id" labelProperty="name" />
    </html:select/>
      

  13.   

    dreamover(梦醒了〖http://hellfire.cn〗) 
    _____________________________________
    正解