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