基本STRUTS标签-学习笔记-Logic标签

BEAN标签(name 是从别处得来的;id是自己的,相当于变量;property相当于变量的值)

前提:

1 String str=request.getParameter("param"); 
2 out.println("str); 

相当于:

 

1 <bean:parameter id="str" name="param"/>
2 <bean:write name="str"/>

 

 写stu.stuId。

<bean:write name="stu" property="stuId"/> 

 

<logic:iterate>

id:遍历的过程中,将其集合内元素起名为id,注意,此时元素可以为JavaBean.

设置name和property:

①数组的情况。

 

1 String[] colors=new String[]{"red","yellow","green"};
2 request.setAttribute("colors", colors);
3  
4 <logic:iterate id="color" name="colors">
5    <bean:write name="color"/>
6 </logic:iterate>

 

 

 ②集合的情况。

 

1 //集合
 2 ArrayLis  books=new ArrayList();
 3 books.add("水浒传");
 4 books.add("西游记");
 5 request.setAttribute("books",books);
 6 
 7 <logic:iterate id="book" name="books">
 8     <bean:write name="book"/>
 9 </logic:iterate>
10 
11 Map map=new HashMap();
12 map.put("1","11");
13 map.put("2", "22");
14 request.setAttribute("map", map);
15 
16 <logic:iterate id="e"  name="map">
17     <bean:write name="e" property="key"/>
18     <bean:write name="e" property="value"/>
19 </logic:iterate>

 

 

 

③某个集合里面有JavaBean的情况。

 1 // include JavaBean:Student
 2 ArrayList stus=new ArrayList();
 3 Student stu1=new Student();
 4 stu1.setStuId("001");
 5 Student stu2=new Student();
 6 stu2.setStuId("002");
 7 Student stu3=new Student();
 8 stu3.setStuId("003");
 9 
10 stus.add(stu1);
11 stus.add(stu2);
12 stus.add(stu3);
13 
14 session.setAttribute("stus",stus);
15 
16 //another page
17 <logic:iterate id="stu" name="stus">
18   <logic:write name="stu" property="stuId"/>
19 </logic:iterate>

 

④Javabean里面有集合的情况。

 1 //include JavaBean:Student & jihe
 2 Student stu4=new Student();
 3 ArrayList phones=new ArrayList();
 4 phones.add("00011");
 5 phones.add("00022");
 6 stu4.setPhones(phones);
 7 session.setAttribute("stu4",stu4);
 8 
 9 //another page
10 
11 <logic:iterate id="phone" name="stu4" property="phones">
12     <logic:write name="phone"/>
13 </loigc:iterate>

 

转载于:https://www.cnblogs.com/hoaprox/p/4526742.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值