struts中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后写入变量名就可以。

附一个网上找的例子:

/*在action里servletRequest.setAttribute(“survey“,survey);
jsp文件片断(注意:不需usebean,标签会自动找):
*/
<nested:write name="survey" property="title"/><br>
 <nested:write name="survey" property="poster"/><br>
 <nested:write name="survey" property="postDate"/><br>
 <nested:iterate id="item" name="survey" property="items" type="survey.SurveyItem">
  <nested:equal name="item" property="type" value="select_single">
        <nested:write  property="title"/><br>
        options:<br>
    <nested:iterate id="option" name="item" property="options" type="survey.SurveyItemOption">
                <nested:write property="index"/>
                <nested:write property="text"/><br>
    </nested:iterate>
  </nested:equal>
  <nested:equal name="item" property="type" value="select_multi">
        <nested:write  property="title"/><br>
   options:<br>
    <nested:iterate id="option" name="item" property="options" type="survey.SurveyItemOption">
                <nested:write property="index"/>
                <nested:write property="text"/><br>
    </nested:iterate>
  </nested:equal>
        <nested:equal name="item" property="type" value="text">
        <nested:write  property="title"/><br>
  </nested:equal>
   </nested:iterate> 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值