logic是structs中的逻辑标签,类似于if/else的逻辑关系,可以通过使用这个标签改变页面布局。
present标签,在cope里(cope包括request,page,session,application)判断name对象的property属性是否存在,如果存在则执行present标签内部的代码。
iterate标签,在cope里判断name对象的property属性是否存在(name.property肯定是或最终转化为collection类型),如果存在则以id为键值循环将name.property的值存入pagecontext中。
iterate标签一般配合<bean:write>标签使用,此标签从pagecontext中以name(这个name要和iterate中的id一致)为键值从pagecontext中取出显示。
实例:
<
logic:presentname
=
"
custInforForm
"
property
=
"
footer
"
>
//
判断custInforForm.getFooter()是否有值,如果有值则执行标签内部的代码
< logic:iterate name = " custInforForm " id = " customer " indexId = " indexId "
property = " footer.dataArray " > // 判断custInforForm.getFooter().getDataArray是否有值,如果有值则循环执行标签内部的代码
< tr >
< td >< inputtype = " checkbox " name = " cbSelect "
value = " <bean:writename= " customer " property= " customerId " /> " ></ td > // 这句的name要等于iterate标签内的id值,要以这个值到pagecontext里取值
< td style = " text-align: center; " ><%= (indexId.intValue() + 1 ) %>
</ td >
< td >< ahref = " # "
onclick = ' toDisplay("<bean:writename="customer"property="customerId"/>") ' >
< bean:write name = " customer " property = " customerId " /> </ a ></ td >
< td >< bean:writename = " customer " property = " customerName " /></ td >
< td >< param:displaytype = " ci.assiManager1 " name = " customer "
property = " customerManagerId " /></ td >
< td >< param:displaytype = " ci.assiManager1 " name = " customer "
property = " customerAssimanagerId " /></ td >
< td >< param:displaytype = " ci.custDep1 " name = " customer "
property = " customerManagerDep " /></ td >
</ tr >
</ logic:iterate >
</ logic:present >
< logic:iterate name = " custInforForm " id = " customer " indexId = " indexId "
property = " footer.dataArray " > // 判断custInforForm.getFooter().getDataArray是否有值,如果有值则循环执行标签内部的代码
< tr >
< td >< inputtype = " checkbox " name = " cbSelect "
value = " <bean:writename= " customer " property= " customerId " /> " ></ td > // 这句的name要等于iterate标签内的id值,要以这个值到pagecontext里取值
< td style = " text-align: center; " ><%= (indexId.intValue() + 1 ) %>
</ td >
< td >< ahref = " # "
onclick = ' toDisplay("<bean:writename="customer"property="customerId"/>") ' >
< bean:write name = " customer " property = " customerId " /> </ a ></ td >
< td >< bean:writename = " customer " property = " customerName " /></ td >
< td >< param:displaytype = " ci.assiManager1 " name = " customer "
property = " customerManagerId " /></ td >
< td >< param:displaytype = " ci.assiManager1 " name = " customer "
property = " customerAssimanagerId " /></ td >
< td >< param:displaytype = " ci.custDep1 " name = " customer "
property = " customerManagerDep " /></ td >
</ tr >
</ logic:iterate >
</ logic:present >
总结:在structs标签中,一般情况下name表示引用一个变量,id表示建立一个变量
在action中:
request.getSession().setAttribute("pageBean",pageBean);
request.setAttribute("result",pageBean.getObjList());
在jsp中:
<logic:present name="result">
<logic:iterate id="book" name="result">
<logic:presentname="book">
<tr>
<td><bean:writename="book" property="name" /></td>
<td><bean:writename="book" property="author" /></td>
<td><bean:writename="book" property="price" /></td>
</tr>
</logic:present>
</logic:iterate>
</logic:present>
<logic:present name="result"scope="session">这里有个scope属性可能是request,session等,name指的是一个对象,可能是javaBean,也可能是集合的对象,整个意思就是就是在scope(session,request)范围里面查找name(一个对象)是否存在,相当于一个if()语句.
在action中:
request.getSession().setAttribute("pageBean",pageBean);
request.setAttribute("result",pageBean.getObjList());
在jsp中:
<logic:present name="result">
</logic:present>
<logic:present name="result"scope="session">这里有个scope属性可能是request,session等,name指的是一个对象,可能是javaBean,也可能是集合的对象,整个意思就是就是在scope(session,request)范围里面查找name(一个对象)是否存在,相当于一个if()语句.