jsp通过logic:iterate或html:optionsCollection循环显示action中传过来的对象List

 
action中代码如下:
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->         List allUser = this .getLoginServiceImpl().find();
        request.setAttribute(
" user " , allUser);
        
return  mapping.findForward( " listUser " );
注:其中User对象有id和name属性

jsp显示:法一
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->              < 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显示:法二
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->        < html:select property = " school " >
           
< html:optionsCollection name = " user "  value = " id "  label = " name " />
       
</ html:select >

optionsCollection标签用法:
与options标签一样,optionsCollection标签可以从集合或者是包含集合的对象里获得选项的标签/值对。在这两种情况里,集合或包含集合的对象必须是一个作用域对象,否则定制标签将无法访问它。

1.与包含集合的对象配合使用
举例:userForm动作表单有一个如下所示的ArrayList类型的userList属性,相应的set,get方法,通过在action中设置好userForm后,request.setAttribute("userForm",userForm);
在jsp页面:
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--> < html:select property = " school " >
< html:optionsCollection name = " userForm "
      property
= " userList " />
</ html:select >

2.与集合配合使用
action中
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--> 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页面
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--> < html:select property = " school " >
< html:optionsCollection name = " userList "
      label
= " label "  value = " value " />
</ html:select >

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值