struts的 <html:option>有三種選項模式,由于最近學習用struts做項目,需要解決下拉列表從數據庫讀值的問題,在網絡上搜索了很久,終于弄清楚了,現總結一下,并且給出例子。
一、FormBean
private List<LabelValueBean> beanCollection;
..... ......
get(),set()方法。
二、Action
.....從數據庫得到返回的List 并將返回的List對象轉換成Iterator類型 遍歷
beanCollection.add(new LabelValueBean(“前臺顯示名稱”,“實際值”);
setBeanCollection(beanCollection);
三、JSP頁面
<html:select property="select" onchange="form.submit();">
<html:optionsCollection name="form名稱" property="beanCollection" />
</html:select>
這樣就解決了。。。