第一、显示一个下拉列表与从别的页面跳转过来没有关系
第二、从数据库中获得数据,你应该在Action里面取得数据后,将数据放到Request里面
第三、数据取出来后放在一个List或Collection或Map里面,我习惯用List
第四、从List或其它的容器中取数据应该用<html:options> 或<html:optionsCollection>
第五、<html:options> 和<html:optionsCollection>外层必须用<html:select property="">,所以这个属性你必须在FormBean里定义
第六、由于你要用到这些标签,所以你必须定义FormBean
第七、示例:
1、从Action取数据,以List为例
List list = xxxxx;//从数据库中取得下拉列表中的数据
request.setAttribute("list",list);
2、在页面显示
<html:form action="xxxx">
...
<html:select property="xxx">
<html:options collection="list" labelProperty="下拉框中显示的内容,一般是name或其它相似属性" property="各选项对应的值,一般是id" />
</html:select>
...
</html:form>
第二、从数据库中获得数据,你应该在Action里面取得数据后,将数据放到Request里面
第三、数据取出来后放在一个List或Collection或Map里面,我习惯用List
第四、从List或其它的容器中取数据应该用<html:options> 或<html:optionsCollection>
第五、<html:options> 和<html:optionsCollection>外层必须用<html:select property="">,所以这个属性你必须在FormBean里定义
第六、由于你要用到这些标签,所以你必须定义FormBean
第七、示例:
1、从Action取数据,以List为例
List list = xxxxx;//从数据库中取得下拉列表中的数据
request.setAttribute("list",list);
2、在页面显示
<html:form action="xxxx">
...
<html:select property="xxx">
<html:options collection="list" labelProperty="下拉框中显示的内容,一般是name或其它相似属性" property="各选项对应的值,一般是id" />
</html:select>
...
</html:form>
解决方案 »
- java程序执行trace
- javaBean有错误吗?
- java wap 论坛
- weblogic缓存的问题
- 探讨一下oracle中有2千万条数据,如果进行模糊查询呢???
- 求一个在SUNappserver下可运行的JMS代码实例?
- 我要开发web数据库程序,用struts合适吗?
- 有关网管软件。请教各位。(来者有份)
- 新手学习tomcat配置遇到头疼问题
- hibernate 的pojo和dto
- oracle10g jdbc驱动+hibernate3实现blob字段映射成byte[]类型时写入没有问题,读出总是不对,谁知道怎么办啊?
- 100分求助 rmi 的问题,在windowes 正常,在linux访问拒绝(有policy,关了防火墙)
<html:select property="provinceId" style="width:110px" styleClass="selectfield">
<html:option value="">省份</html:option>
<html:optionsCollection name="LogManagerFrm" property="beanCollection" styleClass="selectfield"/>
</html:select>
</td>
在你的ACTION里哪到省份列表,然后在你的FORMBEAN里定义一个private beanCollection,并且要把FORMBEAN放到REQUEST里,就是 REQUEST.GETATTRIBUTE("FORMNAME",FORMBEAN) ;
然后在JSP里定义如下:
<html:select property="provinceId" style="width:110px" styleClass="selectfield">
<html:option value="">省份</html:option>
<html:optionsCollection name="LogManagerFrm" property="beanCollection" styleClass="selectfield"/>
</html:select>
</td>
如果是多个,你可以定义多个 beanCollection,例如beanCollection1,只要把JSP的 PROPERTY里的值改成相应的就可以了!