关于struts标签iterate的用法

今天因为要写段前台输出list的代码,用到了iterate,现学现卖,在此总结,省的以后抓瞎。


首先要引进<%@ taglib uri="/tags/struts-nested" prefix="nested"%>

在这次的编码中用到这里的nested:iterate、nested:write俩个标签。

nested:iterate:负责得到action中给出的list

nested:write:负责将list中的内容输出


注意:这里一定要在引用的action所对应的form中对这个list进行set、get,不然jsp页面取不到值。


到action之前正常运行的前提下,JSP页面的编写:


<nested:iterate id="obj" property="list" name="selectUserForm"
            indexId="idx">
            <tr>
                <td><nested:write property="user_id"/></td>
                <td><nested:write property="name" /></td>
                <td><nested:write property="age" /></td>
                <td><nested:write property="sex" /></td>
                <td><nested:write property="birthday" /></td>
                <td>
                <input type="hidden" name="userId" value="<nested:write property='user_id'/>">
                <input type="button" value="删除" id="delete"
                    οnclick="deleteUser()"></input></td>
            </tr>

</nested:iterate>



property表示的是在action的request.setAttribute("list", ***) 中的list,***为我自己定义的将要传值的list。

name:这个一般都被忘记,它是在配置struts时xml中相对应form的<form-bean name="selectUserForm">

         如果缺失,页面将抛异常。

indexId是迭代变量。int型,用的时侯随便起变量名,


nested:write这个标签可以直接将list中的元素解包,直接在property后写入变量名就可以。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值