日期:2014-05-18  浏览次数:20655 次

struts中如何实现下拉列表
如何采用Bean数据的方式填充下拉列表框

------解决方案--------------------
分多阿?开了几个帖子
------解决方案--------------------
用数组的方法填充
------解决方案--------------------
如果存在myList 这个actionform bean
<html:options name= "myList " property= " "/>
property与name一起使用对应的是onform bean的一个变量来描述这个选项的名字
------解决方案--------------------
部门Depart有两个属性
deptId
deptName
分别实现set,get就是bean了


从数据库中取出new Depart()
分别将deptId
deptName付值,
然后加到list
然后request.setAttribute( "departmentsList ",list);传到jsp中

jsp中
<html:select property= "departments ">
<html:options collection= "departmentsList " labelProperty= "deptName " property= "deptId " />
</html:select>

就可以了


------解决方案--------------------
我这个是百分百好使的 记得要给分数啊 首先在action中这样写
try{
conn=ds.getConnection();
stmt=conn.createStatement();
rs=stmt.executeQuery( "select invclassname,pk_invcl from bd_invcl where pk_corp= ' "+pk_corp+ " ' ");
while(rs.next()){
wzlb=new wuzileibie();
wzlb.setKey(rs.getString(1));
wzlb.setValue(rs.getString(2)+ "_ "+rs.getString(1));
list.add(wzlb);
}
request.setAttribute( "wuzileibie_list ", list);
把一个你要填充的放在bean里 然后把bean放在list里,然后在把list放在request里
然后jsp页面这样
---------------------------------
物资类别: <select name= "wuzileibie " style= "width:180px; ">
<option> </option>
<logic:iterate id= "wzlb " name= "wuzileibie_list ">
<bean:define id= "aa " name= "wzlb " property= "value "/>
<option value= <%=aa%> >
<bean:write name= "wzlb " property= "key "/>
</option>
</logic:iterate>
</select>
</logic:present>
------解决方案--------------------
留个痕迹。
------解决方案--------------------
看下struts标签就明明白白了。。
------解决方案--------------------
多看看struts标签就可以了,
------解决方案--------------------
你的理解不对,页面初始化要走action,要不怎么能从你的数据字典中检索出数据添充到下拉菜单呢。。从你的前画面跳转可以跳转到xxx.jsp和xxx.do,假如是xxx.jsp就不走这个画面的action,如果是xxx.do就是先执行画面的action,你把跳转写成xxx.do他就会先执行这个画面的action,在这里,你就可以先检索下拉菜单的数据库连接了,当然你的提交按钮也要走这个action,里面会很乱,那就要在你的跳转后面加参数,如xxx.do?id=xxx,用request.Parameter( "id ")的值来判断在actin中执行不同提交的分支

写的或许不是很清楚,仔细想想,搂主的问题,其实就是一表旦,多提交按钮的处理方式,只不过我把初始化也当初一个提交按钮了,其实意思都一样