jsp通過logic:iterate或html:optionsCollection循環(huán)顯示action中傳過來的對(duì)象List
action中代碼如下:
jsp顯示:法一
optionsCollection標(biāo)簽用法:
與options標(biāo)簽一樣,optionsCollection標(biāo)簽可以從集合或者是包含集合的對(duì)象里獲得選項(xiàng)的標(biāo)簽/值對(duì)。在這兩種情況里,集合或包含集合的對(duì)象必須是一個(gè)作用域?qū)ο螅駝t定制標(biāo)簽將無法訪問它。
1.與包含集合的對(duì)象配合使用
舉例:userForm動(dòng)作表單有一個(gè)如下所示的ArrayList類型的userList屬性,相應(yīng)的set,get方法,通過在action中設(shè)置好userForm后,request.setAttribute("userForm",userForm);
在jsp頁面:
2.與集合配合使用
action中
(注:邊學(xué)邊share,如有問題,歡迎交流學(xué)習(xí))
List allUser=this.getLoginServiceImpl().find();
request.setAttribute("user", allUser);
return mapping.findForward("listUser");
注:其中User對(duì)象有id和name屬性request.setAttribute("user", allUser);
return mapping.findForward("listUser");
jsp顯示:法一
<html:select property="school">
<html:option value="">
<bean:message key="login.select" />
</html:option>
<logic:present name="user">
<logic:iterate id="user" name="user" offset="0">
<option value="<bean:write name="user" property="id" />">
<bean:write name="user" property="name" />
</option>
</logic:iterate>
</logic:present>
</html:select>
jsp顯示:法二<html:option value="">
<bean:message key="login.select" />
</html:option>
<logic:present name="user">
<logic:iterate id="user" name="user" offset="0">
<option value="<bean:write name="user" property="id" />">
<bean:write name="user" property="name" />
</option>
</logic:iterate>
</logic:present>
</html:select>
<html:select property="school">
<html:optionsCollection name="user" value="id" label="name"/>
</html:select>
<html:optionsCollection name="user" value="id" label="name"/>
</html:select>
optionsCollection標(biāo)簽用法:
與options標(biāo)簽一樣,optionsCollection標(biāo)簽可以從集合或者是包含集合的對(duì)象里獲得選項(xiàng)的標(biāo)簽/值對(duì)。在這兩種情況里,集合或包含集合的對(duì)象必須是一個(gè)作用域?qū)ο螅駝t定制標(biāo)簽將無法訪問它。
1.與包含集合的對(duì)象配合使用
舉例:userForm動(dòng)作表單有一個(gè)如下所示的ArrayList類型的userList屬性,相應(yīng)的set,get方法,通過在action中設(shè)置好userForm后,request.setAttribute("userForm",userForm);
在jsp頁面:
<html:select property="school">
<html:optionsCollection name="userForm"
property="userList"/>
</html:select>
<html:optionsCollection name="userForm"
property="userList"/>
</html:select>
2.與集合配合使用
action中
ArrayList userList=new ArrayList();
userList.add(new LabelValueBean("1","haha"));
userList.add(new LabelValueBean("2","dada"));
userList.add(new LabelValueBean("3","xiaoxiao"));
request.setAttribute("userList",userList);
jsp頁面userList.add(new LabelValueBean("1","haha"));
userList.add(new LabelValueBean("2","dada"));
userList.add(new LabelValueBean("3","xiaoxiao"));
request.setAttribute("userList",userList);
<html:select property="school">
<html:optionsCollection name="userList"
label="label" value="value"/>
</html:select>
<html:optionsCollection name="userList"
label="label" value="value"/>
</html:select>
(注:邊學(xué)邊share,如有問題,歡迎交流學(xué)習(xí))
posted on 2007-09-15 23:58 月芽兒 閱讀(6485) 評(píng)論(3) 編輯 收藏 所屬分類: J2EE學(xué)習(xí)心得