浏览 11262 次
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2006-11-06
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2006-11-06
说的简单了啊.不知道有没有理解你的意思.
既然用Struts.就提供一个数据库读取信息到下拉菜单的编码,可以参考,参考 就用如下的用法 LabelValueBean的使用配合<html:select>使用 简单的JDBC读取,没有写全只是一个参考. import org.apache.struts.util.LabelValueBean; ResultSet rs= st.executeQuery(Sql);//查询数据库的信息列表 List lis = new ArrayList(); LabelValueBean lvb = null; while(rs.next()) { lvb = new LabelValueBean(rs.getString(labelName), rs.getString(labelValue)); lis.add(lvb);//把bean添加到集合中. } st.close(); rs.close(); return lis; Action里调用这个方法.用request.setAttribute("namelist",lis); JSP页面用 <html:select style="width:180px;" property="govInvestTypeID"> <html:options collection="namelist" property="value" labelProperty="label" /> </html:select> |
|
返回顶楼 | |
发表时间:2006-11-06
楼上的,先谢了,我测试了
<html:options collection="namelist" property="value" labelProperty="label" /> 其有效范围是在pageContext内的,如果在action内用request.setAttribute()方法,无法在jsp页面正常显示阿? |
|
返回顶楼 | |
发表时间:2006-11-06
我的代码,action中的excute方法:
Vector accounts= new Vector(); accounts.add(new LabelValueBean("00001","00001m")); accounts.add(new LabelValueBean("00002","00002m")); accounts.add(new LabelValueBean("00003","00003m")); request.setAttribute("accounts",accounts); return mapping.findForward("Sucess"); struts-config.xml中的: <form-bean name="AccountSelectForm" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="account" type="java.lang.String" /> <form-property name="descrip" type="java.lang.String" /> </form-bean> <action path="/selectAccount" type="cn.com.clear2pay.epayments.cph.web.SelectAction" name="AccountSelectForm" > <forward name="Sucess" path="/jsp/select/select2.jsp" /> </action> select.jsp中的 <html:form action="selectAccount.do" > <html:select property="account"> <html:options collection="accounts" property="value" labelProperty="label"/> </html:select> </html:form> 那里有错误吗? |
|
返回顶楼 | |