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>